Skip to content

Commit a6449e8

Browse files
committed
Initial commit
0 parents  commit a6449e8

12 files changed

Lines changed: 850 additions & 0 deletions

File tree

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/
8+
*.iws
9+
*.iml
10+
*.ipr
11+
12+
### Eclipse ###
13+
.apt_generated
14+
.classpath
15+
.factorypath
16+
.project
17+
.settings
18+
.springBeans
19+
.sts4-cache
20+
21+
### NetBeans ###
22+
/nbproject/private/
23+
/nbbuild/
24+
/dist/
25+
/nbdist/
26+
/.nb-gradle/
27+
build/
28+
!**/src/main/**/build/
29+
!**/src/test/**/build/
30+
31+
### VS Code ###
32+
.vscode/
33+
34+
### Mac OS ###
35+
.DS_Store
36+
37+
### Extra ###
38+
run/

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# OnixModuleControl
2+
3+
A Nukkit plugin that lets server owners block or modify Onix Client modules or settings for players who join their server.
4+
5+
Tested on [Nukkit](https://github.com/CloudburstMC/Nukkit), [Nukkit-MOT](https://github.com/MemoriesOfTime/Nukkit-MOT), [NukkitPetteriM1Edition](https://github.com/PetteriM1/NukkitPetteriM1Edition) and [PowerNukkitX](https://github.com/PowerNukkitX/PowerNukkitX).
6+
7+
## What it does
8+
9+
> NOTE: Players not using Onix Client will not be affected.
10+
11+
This plugin gives you more control over what players can or can't use when they join your server with Onix Client. Whether you want to block things like Freelook or Hitboxes, or auto-enable helpful features like Double Click Prevent, this plugin makes it easy to do that through a simple config file.
12+
13+
[View the official documentation here](https://onixclient.com/smc).
14+
15+
## Example config
16+
17+
```yaml
18+
# Onix Client Module Control Configuration
19+
# You can find a list of modules here: https://github.com/OnixClient/translations/blob/main/client/languages/en_US.lang
20+
21+
# Verifies blocked_modules, forced_modules and module_settings entry names using https://github.com/OnixClient/translations/blob/main/client/languages/en_US.lang
22+
# If a module or setting doesn't exist or a setting doesn't belong to a module, they'll get ignored
23+
# No verification is done if the lang file couldn't be accessed or parsed
24+
verify_entries: true
25+
26+
# Server name that will be shown in Onix Client UI
27+
server_name: "Server Name"
28+
29+
# Custom notification message (optional, leave empty to use default)
30+
notification_message: ""
31+
32+
# BLOCKED MODULES
33+
# Format:
34+
# module_name:
35+
# block: true
36+
# restriction_reason: "Optional message explaining why it's blocked"
37+
blocked_modules:
38+
module.freelook.name:
39+
block: true
40+
module.hitboxes.name:
41+
block: true
42+
restriction_reason: "Wear your glasses instead."
43+
44+
# FORCED MODULES
45+
# Format:
46+
# module_name:
47+
# force_enable: true
48+
# restriction_reason: "Optional message explaining why it's forced"
49+
# settings:
50+
# setting_name:
51+
# value: setting_value
52+
# min: minimum_value (optional)
53+
# max: maximum_value (optional)
54+
# lock_value: true/false (optional)
55+
# removed_options: [1, 2] (optional, for enum settings)
56+
forced_modules:
57+
module.double_click_prevent.name:
58+
force_enable: true
59+
restriction_reason: "High CPS is not allowed on this server."
60+
settings:
61+
module.double_click_prevent.setting.limit_left_click.name:
62+
value: true
63+
module.double_click_prevent.setting.left_max.name:
64+
max: 17
65+
66+
# MODULE SETTINGS ONLY
67+
# For modules that you don't want to block or force, but just want to change settings
68+
# Format is the same as in the "settings" section above
69+
module_settings:
70+
module.fullbright.name:
71+
settings:
72+
module.fullbright.setting.gamma.name:
73+
max: 3
74+
```
75+
76+
## Result of the example config above
77+
78+
![preview.png](assets/preview.png)

assets/preview.png

8.83 KB
Loading

pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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>de.mariocst</groupId>
8+
<artifactId>OnixModuleControl-NK</artifactId>
9+
<version>1.0</version>
10+
11+
<properties>
12+
<maven.compiler.source>8</maven.compiler.source>
13+
<maven.compiler.target>8</maven.compiler.target>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<repositories>
18+
<repository>
19+
<id>opencollab-repo-release</id>
20+
<url>https://repo.opencollab.dev/maven-releases</url>
21+
</repository>
22+
<repository>
23+
<id>opencollab-repo-snapshot</id>
24+
<url>https://repo.opencollab.dev/maven-snapshots</url>
25+
</repository>
26+
</repositories>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>cn.nukkit</groupId>
31+
<artifactId>nukkit</artifactId>
32+
<version>1.0-SNAPSHOT</version>
33+
<scope>provided</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.projectlombok</groupId>
37+
<artifactId>lombok</artifactId>
38+
<version>1.18.38</version>
39+
</dependency>
40+
</dependencies>
41+
</project>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package de.mariocst.omc;
2+
3+
import cn.nukkit.Nukkit;
4+
import cn.nukkit.Player;
5+
import cn.nukkit.event.EventHandler;
6+
import cn.nukkit.event.Listener;
7+
import cn.nukkit.event.player.PlayerJoinEvent;
8+
import cn.nukkit.network.protocol.ProtocolInfo;
9+
import cn.nukkit.plugin.PluginBase;
10+
import cn.nukkit.utils.Config;
11+
import lombok.Getter;
12+
13+
import java.io.File;
14+
import java.io.IOException;
15+
import java.io.InputStream;
16+
import java.lang.reflect.Constructor;
17+
import java.lang.reflect.InvocationTargetException;
18+
import java.lang.reflect.Method;
19+
import java.nio.file.Files;
20+
21+
public class Main extends PluginBase implements Listener {
22+
@Getter
23+
private static Main instance;
24+
25+
@Getter
26+
private OMCConfig configuration;
27+
28+
private boolean pnx = false;
29+
30+
@Override
31+
public void onEnable() {
32+
instance = this;
33+
34+
this.loadConfiguration();
35+
36+
if (!ReflectionUtils.classExists("cn.nukkit.network.protocol.ScriptMessagePacket")) {
37+
this.getServer().getNetwork().registerPacket(ProtocolInfo.SCRIPT_MESSAGE_PACKET, ScriptMessagePacket.class);
38+
39+
this.info("Registered ScriptMessagePacket class");
40+
}
41+
42+
if (ReflectionUtils.getFieldStr(Nukkit.class, "CODENAME", null).equals("PowerNukkitX"))
43+
this.pnx = true;
44+
45+
this.getServer().getPluginManager().registerEvents(this, this);
46+
47+
this.info("Enabled Onix Module Control");
48+
}
49+
50+
@Override
51+
public void onDisable() {
52+
this.info("Disabled Onix Module Control");
53+
}
54+
55+
public void info(String msg) {
56+
this.getLogger().info(msg);
57+
}
58+
59+
public void warn(String msg) {
60+
this.getLogger().warning(msg);
61+
}
62+
63+
public void loadConfiguration() {
64+
String path = this.getDataFolder() + "/config.yml";
65+
File file = new File(path);
66+
67+
if (!file.exists()) {
68+
try {
69+
if (!file.getParentFile().exists())
70+
Files.createDirectories(file.getParentFile().toPath());
71+
72+
InputStream in = this.getResource("config.yml");
73+
74+
if (in != null)
75+
Files.copy(in, file.toPath());
76+
}
77+
catch (IOException e) {
78+
this.getLogger().critical("Failed to create default config", e);
79+
}
80+
}
81+
82+
Config s = new Config(path, Config.YAML);
83+
this.configuration = new OMCConfig(s.getRootSection());
84+
}
85+
86+
@SuppressWarnings("unused")
87+
@EventHandler
88+
public void onJoin(PlayerJoinEvent event) {
89+
Player player = event.getPlayer();
90+
91+
if (this.pnx) {
92+
try {
93+
Class<?> clazz = Class.forName("cn.nukkit.network.protocol.ScriptMessagePacket");
94+
Constructor<?> ctor = clazz.getConstructor();
95+
Object obj = ctor.newInstance();
96+
97+
ReflectionUtils.setFieldStr(clazz, "channel", obj, "onix_client_event:restrict_features");
98+
ReflectionUtils.setFieldStr(clazz, "message", obj, this.configuration.toJson().toString());
99+
100+
Class<?> playerClass = Class.forName("cn.nukkit.Player");
101+
Class<?> dataPacketClass = Class.forName("cn.nukkit.network.protocol.DataPacket");
102+
Method dataPacket = playerClass.getDeclaredMethod("dataPacket", dataPacketClass);
103+
104+
dataPacket.invoke(player, dataPacketClass.cast(obj));
105+
}
106+
catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException |
107+
InvocationTargetException e) {
108+
this.getLogger().warning("Failed to create or send ScriptMessagePacket", e);
109+
}
110+
}
111+
else {
112+
ScriptMessagePacket packet = new ScriptMessagePacket();
113+
114+
packet.messageId = "onix_client_event:restrict_features";
115+
packet.messageValue = this.configuration.toJson().toString();
116+
117+
player.dataPacket(packet);
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)