Skip to content

Commit e3db14e

Browse files
2.0.0
1 parent d3ea875 commit e3db14e

File tree

9 files changed

+370
-95
lines changed

9 files changed

+370
-95
lines changed

velocity/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>today.netshield.velocity</groupId>
88
<artifactId>NetShield-Velocity</artifactId>
9-
<version>1.1</version>
9+
<version>2.0.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>NetShield-Velocity</name>

velocity/src/main/java/today/netshield/velocity/NetShield.java

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,54 @@
77
import com.velocitypowered.api.plugin.annotation.DataDirectory;
88
import com.velocitypowered.api.proxy.ProxyServer;
99
import lombok.Getter;
10-
import lombok.SneakyThrows;
1110
import org.slf4j.Logger;
11+
12+
import today.netshield.velocity.commands.impl.NetShieldCommand;
1213
import today.netshield.velocity.config.ConfigManager;
13-
import today.netshield.velocity.listeners.PlayerListener;
14+
import today.netshield.velocity.listeners.ConnectionListener;
1415

1516
import java.io.File;
1617
import java.nio.file.Path;
1718

1819
@Plugin(
19-
id = "netshield",
20-
name = "NetShield-Velocity",
21-
version = "1.1",
22-
description = "Secure your minecraft cracked player's accounts."
20+
id = "netshield",
21+
name = "NetShield",
22+
authors = "jsexp",
23+
version = "2.0.0"
2324
)
2425
@Getter
2526
public class NetShield {
26-
@Getter
27-
private static NetShield instance;
2827

29-
@Inject
30-
private static Logger logger;
28+
@Getter private static NetShield instance;
3129

32-
@DataDirectory
33-
@Inject
34-
private Path path;
30+
private final ProxyServer server;
31+
private final Logger logger;
32+
private final ConfigManager configManager;
33+
private final Path dataDirectory;
3534

3635
@Inject
37-
private ProxyServer proxyServer;
36+
public NetShield(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
37+
this.server = server;
38+
this.logger = logger;
39+
this.dataDirectory = dataDirectory;
3840

39-
private ConfigManager configManager;
41+
File configDir = dataDirectory.toFile();
42+
if (!configDir.exists()) {
43+
configDir.mkdirs();
44+
}
4045

41-
@Subscribe
42-
@SneakyThrows
43-
public void onProxyInitialization(ProxyInitializeEvent event) {
46+
this.configManager = new ConfigManager(configDir);
4447
instance = this;
48+
}
4549

46-
File dataFolder = path.toFile();
47-
configManager = new ConfigManager(dataFolder);
48-
49-
configManager.getConfig().node("KEY", "KICK_MESSAGE");
50-
51-
proxyServer.getEventManager().register(this, new PlayerListener());
50+
@Subscribe
51+
public void onProxyInitialization(ProxyInitializeEvent event) {
52+
new NetShieldCommand();
53+
server.getEventManager().register(this, new ConnectionListener(this));
54+
log("NetShield has been enabled!");
5255
}
5356

54-
public void log(String s) {
55-
logger.info(s);
57+
public void log(String message) {
58+
logger.info(message);
5659
}
57-
}
60+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package today.netshield.velocity.commands;
2+
3+
import com.velocitypowered.api.command.CommandManager;
4+
import com.velocitypowered.api.command.SimpleCommand;
5+
import net.kyori.adventure.text.Component;
6+
import net.kyori.adventure.text.TextComponent;
7+
import today.netshield.velocity.NetShield;
8+
import today.netshield.velocity.utils.CC;
9+
10+
/**
11+
* This code was made by jsexp, in case of any unauthorized
12+
* use, at least please leave credits.
13+
* Find more about me @ my <a href="https://github.com/hardcorefactions">GitHub</a> :D
14+
* © 2025 - jsexp
15+
*/
16+
public abstract class BaseCommand implements SimpleCommand {
17+
protected static final Component CONSOLE_SENDER = CC.colorize("&#ff0000Este comando sólo puede ser ejecutado desde el juego.");
18+
19+
public BaseCommand(String name) {
20+
CommandManager manager = NetShield.getInstance().getServer().getCommandManager();
21+
manager.register(
22+
manager.metaBuilder(name)
23+
.plugin(NetShield.getInstance())
24+
.build(),
25+
this);
26+
}
27+
28+
public BaseCommand(String name, String... aliases) {
29+
CommandManager manager = NetShield.getInstance().getServer().getCommandManager();
30+
manager.register(
31+
manager.metaBuilder(name)
32+
.aliases(aliases)
33+
.plugin(NetShield.getInstance())
34+
.build(),
35+
this);
36+
}
37+
38+
@Override
39+
public void execute(Invocation invocation) {
40+
invocation.source().sendMessage(CC.colorize("&#ff0000Este comando no ha sido creado correctamente."));
41+
}
42+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package today.netshield.velocity.commands.impl;
2+
3+
import today.netshield.velocity.NetShield;
4+
import today.netshield.velocity.commands.BaseCommand;
5+
import today.netshield.velocity.utils.CC;
6+
7+
/**
8+
* This code was made by jsexp, in case of any unauthorized
9+
* use, at least please leave credits.
10+
* Find more about me @ my <a href="https://github.com/hardcorefactions">GitHub</a> :D
11+
* © 2025 - jsexp
12+
*/
13+
public class NetShieldCommand extends BaseCommand {
14+
public NetShieldCommand() {
15+
super("netshield", "nsreload");
16+
}
17+
18+
@Override
19+
public void execute(Invocation invocation) {
20+
NetShield.getInstance().getConfigManager().reload();
21+
invocation.source().sendMessage(CC.colorize("&#20bd78La configuración de NetShield ha sido recargada con éxito."));
22+
}
23+
24+
@Override
25+
public boolean hasPermission(Invocation invocation) {
26+
return invocation.source().hasPermission("netshield.admin");
27+
}
28+
}

velocity/src/main/java/today/netshield/velocity/config/ConfigManager.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@Getter
1515
public class ConfigManager {
1616
private final File dataFolder;
17-
private final CommentedConfigurationNode config;
17+
private CommentedConfigurationNode config;
1818

1919
public ConfigManager(File dataFolder) {
2020
this.dataFolder = dataFolder;
@@ -47,4 +47,19 @@ public CommentedConfigurationNode loadConfig(String s) {
4747
throw new RuntimeException(e);
4848
}
4949
}
50-
}
50+
51+
/**
52+
* Reloads the configuration from disk
53+
*
54+
* @return true if the reload was successful, false otherwise
55+
*/
56+
public boolean reload() {
57+
try {
58+
this.config = this.loadConfig("config");
59+
return true;
60+
} catch (Exception e) {
61+
e.printStackTrace();
62+
return false;
63+
}
64+
}
65+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package today.netshield.velocity.listeners;
2+
3+
import com.velocitypowered.api.event.Subscribe;
4+
import com.velocitypowered.api.event.connection.LoginEvent;
5+
import com.velocitypowered.api.proxy.Player;
6+
import java.util.concurrent.CompletableFuture;
7+
import java.util.concurrent.TimeUnit;
8+
9+
import today.netshield.velocity.NetShield;
10+
import today.netshield.velocity.utils.Authentication;
11+
12+
/**
13+
* This code was made by jsexp, in case of any unauthorized
14+
* use, at least please leave credits.
15+
* Find more about me @ my <a href="https://github.com/hardcorefactions">GitHub</a> :D
16+
* © 2025 - jsexp
17+
*/
18+
public class ConnectionListener {
19+
private final NetShield plugin;
20+
private final Authentication authentication;
21+
22+
private static final long AUTH_TIMEOUT_MS = 3000;
23+
24+
public ConnectionListener(NetShield plugin) {
25+
this.plugin = plugin;
26+
this.authentication = new Authentication(plugin);
27+
}
28+
29+
@Subscribe(priority = Short.MAX_VALUE)
30+
public void onLogin(LoginEvent event) {
31+
Player player = event.getPlayer();
32+
plugin.log("Player " + player.getUsername() + " is logging in, starting authentication check");
33+
34+
CompletableFuture<Void> authFuture = authentication.handleAsync(player);
35+
authFuture.orTimeout(AUTH_TIMEOUT_MS, TimeUnit.MILLISECONDS)
36+
.exceptionally(ex -> {
37+
plugin.log("Authentication timed out or failed for player " + player.getUsername() + ": " + ex.getMessage());
38+
return null;
39+
});
40+
41+
}
42+
}

velocity/src/main/java/today/netshield/velocity/listeners/PlayerListener.java

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)