Skip to content

Commit ad45beb

Browse files
committed
Se ha agregado el plugin en Velocity
1 parent 1baec59 commit ad45beb

File tree

8 files changed

+361
-0
lines changed

8 files changed

+361
-0
lines changed

velocity/NetShield-Velocity.iml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module version="4">
3+
<component name="FacetManager">
4+
<facet type="minecraft" name="Minecraft">
5+
<configuration>
6+
<autoDetectTypes>
7+
<platformType>VELOCITY</platformType>
8+
<platformType>ADVENTURE</platformType>
9+
</autoDetectTypes>
10+
<projectReimportVersion>1</projectReimportVersion>
11+
</configuration>
12+
</facet>
13+
</component>
14+
</module>

velocity/pom.xml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>today.netshield.velocity</groupId>
8+
<artifactId>NetShield-Velocity</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>NetShield-Velocity</name>
13+
14+
<properties>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
17+
<maven.compiler.source>17</maven.compiler.source>
18+
<maven.compiler.target>17</maven.compiler.target>
19+
</properties>
20+
21+
<build>
22+
<plugins>
23+
<plugin>
24+
<groupId>org.apache.maven.plugins</groupId>
25+
<artifactId>maven-compiler-plugin</artifactId>
26+
<version>3.11.0</version>
27+
<configuration>
28+
<source>${maven.compiler.target}</source>
29+
<target>${maven.compiler.target}</target>
30+
</configuration>
31+
</plugin>
32+
<plugin>
33+
<groupId>org.apache.maven.plugins</groupId>
34+
<artifactId>maven-shade-plugin</artifactId>
35+
<version>3.5.1</version>
36+
<executions>
37+
<execution>
38+
<phase>package</phase>
39+
<goals>
40+
<goal>shade</goal>
41+
</goals>
42+
<configuration>
43+
<createDependencyReducedPom>false</createDependencyReducedPom>
44+
<filters>
45+
<filter>
46+
<artifact>*:*</artifact>
47+
<excludes>
48+
<exclude>META-INF/*.SF</exclude>
49+
<exclude>META-INF/*.DSA</exclude>
50+
<exclude>META-INF/*.RSA</exclude>
51+
</excludes>
52+
</filter>
53+
</filters>
54+
</configuration>
55+
</execution>
56+
</executions>
57+
</plugin>
58+
</plugins>
59+
<resources>
60+
<resource>
61+
<directory>src/main/resources</directory>
62+
<filtering>true</filtering>
63+
</resource>
64+
</resources>
65+
</build>
66+
67+
<repositories>
68+
<repository>
69+
<id>papermc-repo</id>
70+
<url>https://repo.papermc.io/repository/maven-public/</url>
71+
</repository>
72+
<repository>
73+
<id>nickuc-repo</id>
74+
<url>https://repo.nickuc.com/maven-releases/</url>
75+
</repository>
76+
</repositories>
77+
78+
<dependencies>
79+
<!-- Configurate YAML -->
80+
<dependency>
81+
<groupId>org.spongepowered</groupId>
82+
<artifactId>configurate-yaml</artifactId>
83+
<version>4.1.2</version>
84+
<scope>compile</scope>
85+
</dependency>
86+
87+
<!-- Velocity API -->
88+
<dependency>
89+
<groupId>com.velocitypowered</groupId>
90+
<artifactId>velocity-api</artifactId>
91+
<version>3.3.0-SNAPSHOT</version>
92+
<scope>provided</scope>
93+
</dependency>
94+
95+
<!-- nLogin -->
96+
<dependency>
97+
<groupId>com.nickuc.login</groupId>
98+
<artifactId>nlogin-api</artifactId>
99+
<version>10.2</version>
100+
<scope>provided</scope>
101+
</dependency>
102+
103+
<!-- OkHTTP3 -->
104+
<dependency>
105+
<groupId>com.squareup.okhttp3</groupId>
106+
<artifactId>okhttp</artifactId>
107+
<version>4.12.0</version>
108+
<scope>compile</scope>
109+
</dependency>
110+
<dependency>
111+
<groupId>org.projectlombok</groupId>
112+
<artifactId>lombok</artifactId>
113+
<version>1.18.30</version>
114+
<scope>compile</scope>
115+
</dependency>
116+
</dependencies>
117+
</project>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package today.netshield.velocity;
2+
3+
import com.google.inject.Inject;
4+
import com.velocitypowered.api.event.Subscribe;
5+
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
6+
import com.velocitypowered.api.plugin.Plugin;
7+
import com.velocitypowered.api.plugin.annotation.DataDirectory;
8+
import com.velocitypowered.api.proxy.ProxyServer;
9+
import lombok.Getter;
10+
import lombok.SneakyThrows;
11+
import org.slf4j.Logger;
12+
import today.netshield.velocity.config.ConfigManager;
13+
import today.netshield.velocity.hook.impl.nLogin;
14+
15+
import java.io.File;
16+
import java.nio.file.Path;
17+
18+
@Plugin(
19+
id = "netshield",
20+
name = "NetShield-Velocity",
21+
version = "1.0-SNAPSHOT",
22+
description = "Secure your minecraft cracked player's accounts."
23+
)
24+
@Getter
25+
public class NetShield {
26+
@Getter
27+
private static NetShield instance;
28+
@Inject
29+
private static Logger logger;
30+
31+
@DataDirectory
32+
@Inject
33+
private Path path;
34+
35+
@Inject
36+
private ProxyServer proxyServer;
37+
38+
private ConfigManager configManager;
39+
40+
@Subscribe
41+
@SneakyThrows
42+
public void onProxyInitialization(ProxyInitializeEvent event) {
43+
instance = this;
44+
45+
File dataFolder = path.toFile();
46+
configManager = new ConfigManager(dataFolder);
47+
48+
configManager.getConfig().node("KEY", "KICK_MESSAGE");
49+
50+
loadListeners();
51+
}
52+
53+
private void loadListeners() {
54+
if (getProxyServer().getPluginManager().isLoaded("nlogin")) {
55+
proxyServer.getEventManager().register(this, new nLogin());
56+
}
57+
}
58+
59+
public static void log(String s) {
60+
logger.info(s);
61+
}
62+
63+
public File getFile(String file) {
64+
return new File(path.toFile(), file);
65+
}
66+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package today.netshield.velocity.config;
2+
3+
import lombok.Getter;
4+
import lombok.SneakyThrows;
5+
import org.spongepowered.configurate.CommentedConfigurationNode;
6+
import org.spongepowered.configurate.ConfigurateException;
7+
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
8+
9+
import java.io.File;
10+
import java.io.InputStream;
11+
import java.nio.file.Files;
12+
import java.nio.file.StandardCopyOption;
13+
14+
@Getter
15+
public class ConfigManager {
16+
private final File dataFolder;
17+
private final CommentedConfigurationNode config;
18+
19+
public ConfigManager(File dataFolder) {
20+
this.dataFolder = dataFolder;
21+
this.dataFolder.mkdir();
22+
23+
this.config = this.loadConfig("config");
24+
}
25+
26+
@SneakyThrows
27+
public CommentedConfigurationNode loadConfig(String s) {
28+
File file = new File(dataFolder, s + ".yml");
29+
30+
if (!file.exists()) {
31+
try (InputStream in = getClass().getClassLoader().getResourceAsStream(s + ".yml")) {
32+
file.createNewFile();
33+
assert in != null;
34+
Files.copy(in, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
35+
}
36+
}
37+
38+
YamlConfigurationLoader yamlConfigurationLoader = YamlConfigurationLoader.builder()
39+
.path(file.toPath())
40+
.build();
41+
42+
CommentedConfigurationNode config;
43+
try {
44+
config = yamlConfigurationLoader.load();
45+
return config;
46+
} catch (ConfigurateException e) {
47+
throw new RuntimeException(e);
48+
}
49+
}
50+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package today.netshield.velocity.hook;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonObject;
5+
import com.velocitypowered.api.proxy.Player;
6+
import lombok.SneakyThrows;
7+
import net.kyori.adventure.text.Component;
8+
import okhttp3.*;
9+
import org.spongepowered.configurate.CommentedConfigurationNode;
10+
import org.spongepowered.configurate.serialize.SerializationException;
11+
import today.netshield.velocity.NetShield;
12+
import today.netshield.velocity.config.ConfigManager;
13+
import today.netshield.velocity.utils.CC;
14+
15+
import java.io.IOException;
16+
import java.util.List;
17+
18+
public class Authentication {
19+
private final ConfigManager configManager = NetShield.getInstance().getConfigManager();
20+
21+
public void handle(Player player) {
22+
OkHttpClient client = new OkHttpClient();
23+
24+
String jsonString = getString(player);
25+
26+
RequestBody requestBody = RequestBody.create(jsonString, MediaType.parse("application/json"));
27+
28+
Request request = new Request.Builder()
29+
.url("https://netshield.bombardeen.me/api/checkuser")
30+
.post(requestBody)
31+
.addHeader("Content-Type", "application/json")
32+
.build();
33+
34+
try (Response response = client.newCall(request).execute()) {
35+
if (response.isSuccessful()) {
36+
String jsonResponse = response.body().string();
37+
String code = jsonResponse.contains("\"code\"") ?
38+
jsonResponse.split("\"code\"")[1].split(":")[1].split(",")[0].replaceAll("\"", "").trim() : null;
39+
40+
if (code == null || !code.equalsIgnoreCase("VALID_PLAYER")) {
41+
kickPlayer(player);
42+
}
43+
} else {
44+
NetShield.log("Error: " + response.code() + " - " + response.message());
45+
}
46+
} catch (IOException ignored) {}
47+
}
48+
49+
private String getString(Player player) {
50+
Gson gson = new Gson();
51+
CommentedConfigurationNode config = configManager.getConfig();
52+
53+
JsonObject jsonObject = new JsonObject();
54+
jsonObject.addProperty("key", config.node("KEY").getString());
55+
56+
JsonObject playerData = new JsonObject();
57+
playerData.addProperty("name", player.getUsername());
58+
playerData.addProperty("ip", player.getRemoteAddress().getAddress().getHostAddress());
59+
60+
jsonObject.add("playerData", playerData);
61+
62+
return gson.toJson(jsonObject);
63+
}
64+
65+
@SneakyThrows
66+
private void kickPlayer(Player player) throws SerializationException {
67+
CommentedConfigurationNode config = configManager.getConfig();
68+
List<String> kickMessage = config.node("KICK_MESSAGE").getList(String.class);
69+
70+
StringBuilder message = new StringBuilder();
71+
for (String line : kickMessage) {
72+
message.append(CC.colorize(line)).append("\n");
73+
}
74+
player.disconnect(Component.text(message.toString()));
75+
}
76+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package today.netshield.velocity.hook.impl;
2+
3+
import com.nickuc.login.api.event.velocity.auth.LoginEvent;
4+
import com.nickuc.login.api.event.velocity.auth.RegisterEvent;
5+
import com.velocitypowered.api.event.Subscribe;
6+
import today.netshield.velocity.hook.Authentication;
7+
8+
public class nLogin {
9+
private final Authentication authentication = new Authentication();
10+
@Subscribe
11+
public void onPlayerLogin(LoginEvent event) {
12+
authentication.handle(event.getPlayer());
13+
}
14+
15+
@Subscribe
16+
public void onPlayerRegister(RegisterEvent event) {
17+
authentication.handle(event.getPlayer());
18+
}
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package today.netshield.velocity.utils;
2+
3+
import net.kyori.adventure.text.Component;
4+
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
5+
6+
public class CC {
7+
public static Component colorize(String string) {
8+
return LegacyComponentSerializer.legacyAmpersand().deserialize(string);
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
KEY: "YOUR-KEY-HERE"
2+
3+
KICK_MESSAGE:
4+
- "&b&lNet&9&lShield &7&m-&f Blocked"
5+
- "&f"
6+
- "&cYour account is blocked from the &lNetShield&c network."
7+
- "&cIf you think this is an error. Contact us at Discord."
8+
- "&f"
9+
- "&9Discord &7» &fdiscord.gg/netshield"

0 commit comments

Comments
 (0)