generated from Lenni0451/GradleTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
128 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
# Gradle Template | ||
A template project for my gradle based repos. | ||
# ViaProxyWhitelist | ||
Only allow specified players to join the ViaProxy server. | ||
|
||
## Maven Server Setup | ||
To use the maven servers in this template you need to enter your credentials into your `gradle.properties` files.\ | ||
The file can be found in the `.gradle` folder in your home directory (create it if it doesn't exist). | ||
```properties | ||
reposiliteUsername=user | ||
reposilitePassword=123456 | ||
## Usage | ||
### Installation | ||
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.\ | ||
The minimum required version of ViaProxy is `3.3.4`. | ||
|
||
ossrhUsername=user | ||
ossrhPassword=123456 | ||
``` | ||
### Configuration | ||
You must enable the `proxy-online-mode` option in the config!\ | ||
The plugin does not work without this option enabled. | ||
|
||
## Signing Setup | ||
To sign your artifacts you need to enter your signing credentials into your `gradle.properties` files.\ | ||
The file can be found in the `.gradle` folder in your home directory (create it if it doesn't exist). | ||
```properties | ||
signing.keyId=ABC12345 | ||
signing.password=123456 | ||
signing.secretKeyRingFile=secretkey.gpg | ||
``` | ||
After starting the server with the plugin, a `whitelist.yml` file will be created in the server folder.\ | ||
It contains the kick message and the list of players that are allowed to join the server. | ||
|
||
```yaml | ||
#The message that will be displayed when a player is not whitelisted | ||
KickMessage: You are not whitelisted on this server! | ||
|
||
The secretkey can be exported using the `gpg` command: | ||
```bash | ||
gpg --export-secret-key > secretkey.gpg | ||
#The list of players that are allowed to join the server | ||
Whitelist: | ||
- Player1 | ||
- Player2 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package net.lenni0451.whitelist; | ||
|
||
import io.netty.channel.ChannelFutureListener; | ||
import net.raphimc.netminecraft.packet.Packet; | ||
import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket; | ||
import net.raphimc.viaproxy.proxy.packethandler.PacketHandler; | ||
import net.raphimc.viaproxy.proxy.session.ProxyConnection; | ||
|
||
import java.util.List; | ||
|
||
public class LoginListener extends PacketHandler { | ||
|
||
public LoginListener(final ProxyConnection proxyConnection) { | ||
super(proxyConnection); | ||
} | ||
|
||
@Override | ||
public boolean handleC2P(Packet packet, List<ChannelFutureListener> listeners) { | ||
if (packet instanceof C2SLoginHelloPacket loginHello) { | ||
if (!WhitelistConfig.whitelist.contains(loginHello.name)) { | ||
this.proxyConnection.kickClient(WhitelistConfig.kickMessage); | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.lenni0451.whitelist; | ||
|
||
import net.lenni0451.lambdaevents.EventHandler; | ||
import net.raphimc.viaproxy.ViaProxy; | ||
import net.raphimc.viaproxy.plugins.ViaProxyPlugin; | ||
import net.raphimc.viaproxy.plugins.events.ConnectEvent; | ||
import net.raphimc.viaproxy.plugins.events.ViaProxyLoadedEvent; | ||
import net.raphimc.viaproxy.util.logging.Logger; | ||
|
||
public class Main extends ViaProxyPlugin { | ||
|
||
@Override | ||
public void onEnable() { | ||
WhitelistConfig.load(); | ||
ViaProxy.EVENT_MANAGER.register(this); | ||
} | ||
|
||
@EventHandler | ||
public void onViaProxyLoaded(final ViaProxyLoadedEvent event) { | ||
if (!ViaProxy.getConfig().isProxyOnlineMode()) { | ||
Logger.LOGGER.error("Proxy online mode is disabled, please enable it to use the whitelist plugin!"); | ||
Logger.LOGGER.error("Without online mode the whitelist plugin would be effectively useless"); | ||
Logger.LOGGER.error("Shutting down..."); | ||
System.exit(0); | ||
} | ||
} | ||
|
||
@EventHandler(priority = Integer.MIN_VALUE) | ||
public void onConnect(final ConnectEvent event) { | ||
event.getProxyConnection().getPacketHandlers().add(0, new LoginListener(event.getProxyConnection())); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/net/lenni0451/whitelist/WhitelistConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.lenni0451.whitelist; | ||
|
||
import net.lenni0451.optconfig.ConfigLoader; | ||
import net.lenni0451.optconfig.annotations.Description; | ||
import net.lenni0451.optconfig.annotations.OptConfig; | ||
import net.lenni0451.optconfig.annotations.Option; | ||
import net.lenni0451.optconfig.provider.ConfigProvider; | ||
import net.raphimc.viaproxy.util.logging.Logger; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
@OptConfig | ||
public class WhitelistConfig { | ||
|
||
@Option("KickMessage") | ||
@Description("The message that will be displayed when a player is not whitelisted") | ||
public static String kickMessage = "You are not whitelisted on this server!"; | ||
|
||
@Option("Whitelist") | ||
@Description("The list of players that are allowed to join the server") | ||
public static List<String> whitelist = List.of("Player1", "Player2"); | ||
|
||
public static void load() { | ||
try { | ||
ConfigLoader<WhitelistConfig> configLoader = new ConfigLoader<>(WhitelistConfig.class); | ||
configLoader.getConfigOptions().setResetInvalidOptions(true); | ||
configLoader.loadStatic(ConfigProvider.file(new File("whitelist.yml"))); | ||
} catch (Throwable t) { | ||
Logger.LOGGER.error("Failed to load the whitelist configuration!", t); | ||
System.exit(-1); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: "Whitelist" | ||
version: "${version}" | ||
author: "Lenni0451" | ||
main: "net.lenni0451.whitelist.Main" | ||
min-version: "3.3.4" |