Skip to content

Commit 387083f

Browse files
committed
Admin Command for Velocity
1 parent 9410701 commit 387083f

3 files changed

Lines changed: 90 additions & 26 deletions

File tree

assembly/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ shadowJar {
2222
relocate('dev.dejvokep.boostedyaml', 'com.xinecraft.minetrax.libs.dejvokep.boostedyaml')
2323
relocate('okio', 'com.xinecraft.minetrax.libs.okio')
2424
relocate('okhttp3', 'com.xinecraft.minetrax.libs.okhttp3')
25-
relocate('net.kyori', 'com.xinecraft.minetrax.libs.kyori')
2625
relocate('de.themoep', 'com.xinecraft.minetrax.libs.themoep')
26+
27+
/**
28+
* Note: Kyori's relocation causes issue with Velocity.
29+
* We can't use adventure functions in velocity if its relocated.
30+
* Keeping it commented for sometime to see if not relocating it fixes the issue with Bukkit.
31+
*/
32+
// relocate('net.kyori', 'com.xinecraft.minetrax.libs.kyori')
2733
}

velocity/src/main/java/com/xinecraft/minetrax/velocity/MinetraxVelocity.java

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.xinecraft.minetrax.common.interfaces.MinetraxPlugin;
1818
import com.xinecraft.minetrax.common.utils.LoggingUtil;
1919
import com.xinecraft.minetrax.common.webquery.WebQueryServer;
20+
import com.xinecraft.minetrax.velocity.commands.MinetraxAdminCommand;
2021
import com.xinecraft.minetrax.velocity.hooks.skinsrestorer.SkinsRestorerHook;
2122
import com.xinecraft.minetrax.velocity.listeners.ServerConnectedListener;
2223
import com.xinecraft.minetrax.velocity.logging.VelocityLogger;
@@ -47,15 +48,7 @@
4748
import java.util.concurrent.TimeUnit;
4849

4950
@Getter
50-
@Plugin(
51-
id = "minetrax",
52-
name = "Minetrax",
53-
authors = {"Xinecraft"},
54-
version = BuildConstants.VERSION,
55-
dependencies = {
56-
@Dependency(id = "skinsrestorer", optional = true)
57-
}
58-
)
51+
@Plugin(id = "minetrax", name = "Minetrax", authors = {"Xinecraft"}, version = BuildConstants.VERSION, dependencies = {@Dependency(id = "skinsrestorer", optional = true)})
5952
public class MinetraxVelocity implements MinetraxPlugin {
6053
@Inject
6154
private Logger logger;
@@ -108,19 +101,13 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
108101
return;
109102
}
110103
// Disable plugin if host, key, secret or server-id is not there
111-
if (
112-
apiHost == null || apiKey == null || apiSecret == null || apiServerId == null ||
113-
apiHost.isEmpty() || apiKey.isEmpty() || apiSecret.isEmpty() || apiServerId.isEmpty()
114-
) {
104+
if (apiHost == null || apiKey == null || apiSecret == null || apiServerId == null || apiHost.isEmpty() || apiKey.isEmpty() || apiSecret.isEmpty() || apiServerId.isEmpty()) {
115105
logger.error("Plugin disabled due to no API information");
116106
return;
117107
}
118108

119109
// GSON builder
120-
gson = new GsonBuilder()
121-
.serializeNulls()
122-
.disableHtmlEscaping()
123-
.create();
110+
gson = new GsonBuilder().serializeNulls().disableHtmlEscaping().create();
124111

125112
// Setup Common
126113
common = new MinetraxCommon();
@@ -149,13 +136,12 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
149136
// Register Listeners
150137
proxyServer.getEventManager().register(this, new ServerConnectedListener());
151138

139+
// Register Commands
140+
proxyServer.getCommandManager().register("minetraxv", new MinetraxAdminCommand(this), "mtxv");
141+
152142
// Register Tasks
153143
if (isServerIntelEnabled) {
154-
proxyServer.getScheduler()
155-
.buildTask(plugin, new ServerIntelReportTask())
156-
.delay(60L, TimeUnit.SECONDS)
157-
.repeat(60L, TimeUnit.SECONDS)
158-
.schedule();
144+
proxyServer.getScheduler().buildTask(plugin, new ServerIntelReportTask()).delay(60L, TimeUnit.SECONDS).repeat(60L, TimeUnit.SECONDS).schedule();
159145
}
160146
}
161147

@@ -167,9 +153,7 @@ private void startWebQueryServer() {
167153
private void loadConfig() {
168154
// Create and update the file
169155
try {
170-
config = YamlDocument.create(new File(getDataPath().toFile(), "config.yml"),
171-
Objects.requireNonNull(getClass().getResourceAsStream("/velocityConfig.yml")),
172-
GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setVersioning(new BasicVersioning("file-version")).build());
156+
config = YamlDocument.create(new File(getDataPath().toFile(), "config.yml"), Objects.requireNonNull(getClass().getResourceAsStream("/velocityConfig.yml")), GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setVersioning(new BasicVersioning("file-version")).build());
173157
} catch (IOException ex) {
174158
LoggingUtil.warntrace(ex);
175159
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.xinecraft.minetrax.velocity.commands;
2+
3+
import com.velocitypowered.api.command.SimpleCommand;
4+
import com.velocitypowered.api.command.CommandSource;
5+
import com.velocitypowered.api.proxy.ConsoleCommandSource;
6+
import com.xinecraft.minetrax.common.MinetraxCommon;
7+
import com.xinecraft.minetrax.common.enums.BanWardenSyncType;
8+
import com.xinecraft.minetrax.velocity.MinetraxVelocity;
9+
import net.kyori.adventure.text.Component;
10+
import net.kyori.adventure.text.format.NamedTextColor;
11+
12+
public class MinetraxAdminCommand implements SimpleCommand {
13+
private final MinetraxVelocity plugin;
14+
15+
public MinetraxAdminCommand(MinetraxVelocity plugin) {
16+
this.plugin = plugin;
17+
}
18+
19+
@Override
20+
public void execute(Invocation invocation) {
21+
CommandSource source = invocation.source();
22+
String[] args = invocation.arguments();
23+
24+
if (args.length == 0) {
25+
usage(source);
26+
return;
27+
}
28+
29+
String firstArg = args[0];
30+
if (firstArg.equalsIgnoreCase("help") || firstArg.equalsIgnoreCase("?")) {
31+
usage(source);
32+
return;
33+
}
34+
35+
if (firstArg.equalsIgnoreCase("banwarden:sync")) {
36+
if (!(source instanceof ConsoleCommandSource)) {
37+
source.sendMessage(Component.text("This command can only be run from console.", NamedTextColor.RED));
38+
return;
39+
}
40+
41+
String secondArg = args.length > 1 ? args[1].toLowerCase() : "all";
42+
source.sendMessage(Component.text("[BanWarden] Syncing " + secondArg + " punishments to web, plz check server logs for progress...", NamedTextColor.GREEN));
43+
banwardenSyncBans(secondArg);
44+
return;
45+
}
46+
}
47+
48+
private void usage(CommandSource source) {
49+
source.sendMessage(Component.text("Minetrax Admin Commands:", NamedTextColor.AQUA));
50+
source.sendMessage(Component.text("/mtxv banwarden:sync", NamedTextColor.GREEN));
51+
source.sendMessage(Component.text(" Sync bans from ban plugin to minetrax website.", NamedTextColor.GRAY));
52+
source.sendMessage(Component.text("/mtxv help", NamedTextColor.GREEN));
53+
source.sendMessage(Component.text(" Shows help message.", NamedTextColor.GRAY));
54+
}
55+
56+
private void banwardenSyncBans(String typeString) {
57+
if (!plugin.getIsBanWardenEnabled()) {
58+
plugin.getLogger().warn("BanWarden is not enabled, cannot sync bans.");
59+
return;
60+
}
61+
62+
BanWardenSyncType syncType = switch (typeString) {
63+
case "active" -> BanWardenSyncType.ACTIVE;
64+
case "inactive" -> BanWardenSyncType.INACTIVE;
65+
default -> BanWardenSyncType.ALL;
66+
};
67+
MinetraxCommon.getInstance().getBanWarden().sync(syncType);
68+
}
69+
70+
@Override
71+
public boolean hasPermission(final Invocation invocation) {
72+
return invocation.source().hasPermission("minetrax.admin");
73+
}
74+
}

0 commit comments

Comments
 (0)