Skip to content

Commit 9410701

Browse files
committed
Init BanWarden for Proxy
1 parent 6d1c2b3 commit 9410701

7 files changed

Lines changed: 101 additions & 48 deletions

File tree

bukkit/src/main/java/com/xinecraft/minetrax/bukkit/MinetraxBukkit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ private void initVariables() {
345345
isSendInventoryDataToPlayerIntel = this.getConfig().getBoolean("send-inventory-data-to-player-intel");
346346
isDisablePlayerMovementTracking = this.getConfig().getBoolean("disable-player-movement-tracking");
347347
isSkinsRestorerHookEnabled = this.getConfig().getBoolean("enable-skinsrestorer-hook");
348-
serverSessionId = UUID.randomUUID().toString();
349348
isBanWardenEnabled = this.getConfig().getBoolean("enable-banwarden");
349+
serverSessionId = UUID.randomUUID().toString();
350350
}
351351

352352
private void startWebQueryServer() {

bukkit/src/main/java/com/xinecraft/minetrax/bukkit/commands/MinetraxAdminCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command
3131
}
3232

3333
String secondArg = strings.length > 1 ? strings[1].toLowerCase() : "all";
34-
commandSender.sendMessage(ChatColor.GREEN + "[BanWarden] Syncing " + secondArg + " ban data to web, plz check server logs for progress...");
34+
commandSender.sendMessage(ChatColor.GREEN + "[BanWarden] Syncing " + secondArg + " punishments to web, plz check server logs for progress...");
3535
banwardenSyncBans(secondArg);
3636
return true;
3737
}

bungee/src/main/java/com/xinecraft/minetrax/bungee/MinetraxBungee.java

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
import com.xinecraft.minetrax.bungee.utils.PluginUtil;
1111
import com.xinecraft.minetrax.bungee.webquery.BungeeWebQuery;
1212
import com.xinecraft.minetrax.common.MinetraxCommon;
13-
import com.xinecraft.minetrax.common.interfaces.MinetraxPlugin;
13+
import com.xinecraft.minetrax.common.enums.BanWardenPluginType;
1414
import com.xinecraft.minetrax.common.enums.PlatformType;
15+
import com.xinecraft.minetrax.common.interfaces.MinetraxPlugin;
1516
import com.xinecraft.minetrax.common.webquery.WebQueryServer;
1617
import lombok.Getter;
1718
import net.md_5.bungee.api.plugin.Plugin;
1819
import net.md_5.bungee.config.Configuration;
1920
import net.md_5.bungee.config.ConfigurationProvider;
2021
import net.md_5.bungee.config.YamlConfiguration;
21-
import net.skinsrestorer.api.SkinsRestorer;
2222
import net.skinsrestorer.api.SkinsRestorerProvider;
2323
import net.skinsrestorer.api.VersionProvider;
2424
import net.skinsrestorer.api.event.SkinApplyEvent;
@@ -28,7 +28,6 @@
2828
import java.io.IOException;
2929
import java.nio.file.Files;
3030
import java.nio.file.StandardCopyOption;
31-
import java.util.HashMap;
3231
import java.util.List;
3332
import java.util.UUID;
3433
import java.util.concurrent.ConcurrentHashMap;
@@ -58,25 +57,12 @@ public final class MinetraxBungee extends Plugin implements MinetraxPlugin {
5857
public ConcurrentHashMap<String, String> joinAddressCache = new ConcurrentHashMap<>();
5958
public Boolean hasSkinsRestorer = false;
6059
public Boolean isSkinsRestorerHookEnabled;
60+
public Boolean isBanWardenEnabled = false;
6161
public Gson gson = null;
6262
private MinetraxCommon common;
6363

6464
@Override
6565
public void onEnable() {
66-
// GSON builder
67-
gson = new GsonBuilder()
68-
.serializeNulls()
69-
.disableHtmlEscaping()
70-
.create();
71-
72-
// Setup Common
73-
common = new MinetraxCommon();
74-
common.setPlugin(this);
75-
common.setPlatformType(PlatformType.BUNGEE);
76-
common.setGson(gson);
77-
common.setLogger(new BungeeLogger(this));
78-
common.setScheduler(new BungeeScheduler(this));
79-
common.setWebQuery(new BungeeWebQuery(this));
8066
plugin = this;
8167

8268
// Load configuration
@@ -95,6 +81,22 @@ public void onEnable() {
9581
return;
9682
}
9783

84+
// GSON builder
85+
gson = new GsonBuilder()
86+
.serializeNulls()
87+
.disableHtmlEscaping()
88+
.create();
89+
90+
// Setup Common
91+
common = new MinetraxCommon();
92+
common.setPlugin(this);
93+
common.setPlatformType(PlatformType.BUNGEE);
94+
common.setGson(gson);
95+
common.setLogger(new BungeeLogger(this));
96+
common.setScheduler(new BungeeScheduler(this));
97+
common.setWebQuery(new BungeeWebQuery(this));
98+
initBanWarden(common);
99+
98100
// init Bstats
99101
initBstats();
100102

@@ -169,6 +171,7 @@ private void initVariables() {
169171
isAllowOnlyWhitelistedCommandsFromWeb = config.getBoolean("allow-only-whitelisted-commands-from-web", false);
170172
whitelistedCommandsFromWeb = config.getStringList("whitelisted-commands-from-web");
171173
isSkinsRestorerHookEnabled = config.getBoolean("enable-skinsrestorer-hook", false);
174+
isBanWardenEnabled = config.getBoolean("enable-banwarden", false);
172175
serverSessionId = UUID.randomUUID().toString();
173176
}
174177

@@ -207,4 +210,24 @@ private Boolean setupSkinsRestorer() {
207210
return false;
208211
}
209212
}
213+
214+
private void initBanWarden(MinetraxCommon common) {
215+
if (!isBanWardenEnabled) {
216+
getLogger().warning("[BanWarden] BanWarden is disabled in config.yml");
217+
return;
218+
}
219+
220+
// set which ban plugin is enabled.
221+
if (PluginUtil.checkIfPluginEnabled("LiteBans")) {
222+
common.initBanWarden(BanWardenPluginType.LITEBANS);
223+
} else if (PluginUtil.checkIfPluginEnabled("LibertyBans")) {
224+
common.initBanWarden(BanWardenPluginType.LIBERTYBANS);
225+
} else if (PluginUtil.checkIfPluginEnabled("AdvancedBan")) {
226+
common.initBanWarden(BanWardenPluginType.ADVANCEDBAN);
227+
} else {
228+
isBanWardenEnabled = false;
229+
getLogger().warning("[BanWarden] No supported BanWarden plugin found.");
230+
return;
231+
}
232+
}
210233
}

common/src/main/java/com/xinecraft/minetrax/common/banwarden/hooks/LibertybansHook.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void accept(PostPunishEvent event) {
7373
Punishment punishment = event.getPunishment();
7474
MinetraxCommon.getInstance().getScheduler().runAsync(() -> {
7575
try {
76-
PunishmentData data = convertPunishmentToData(punishment, true, null);
76+
PunishmentData data = convertPunishmentToData(punishment, true, null, "punish");
7777
ReportPlayerPunishment.reportSync(data);
7878
} catch (Exception e) {
7979
LoggingUtil.error("[BanWarden] PunishEvent -> Error reporting event to Minetrax: " + e.getMessage());
@@ -89,7 +89,7 @@ public void accept(PostPardonEvent event) {
8989
Operator operator = event.getOperator();
9090
MinetraxCommon.getInstance().getScheduler().runAsync(() -> {
9191
try {
92-
PunishmentData data = convertPunishmentToData(punishment, false, operator);
92+
PunishmentData data = convertPunishmentToData(punishment, false, operator, "pardon");
9393
ReportPlayerPunishment.reportSync(data);
9494
} catch (Exception e) {
9595
LoggingUtil.error("[BanWarden] PardonEvent -> Error reporting event to Minetrax: " + e.getMessage());
@@ -117,7 +117,7 @@ public ReactionStage<Void> apply(Void unused) {
117117
// Process the current chunk
118118
List<PunishmentData> punishmentDataList = new ArrayList<>();
119119
punishmentList.forEach(punishment -> {
120-
PunishmentData data = convertPunishmentToData(punishment, true, null);
120+
PunishmentData data = convertPunishmentToData(punishment, true, null, "sync");
121121
punishmentDataList.add(data);
122122
});
123123

@@ -174,7 +174,7 @@ private BanWardenPunishmentType getBanWardenPunishmentType(PunishmentType type)
174174
};
175175
}
176176

177-
private PunishmentData convertPunishmentToData(Punishment punishment, boolean isActive, Operator pardonOperator) {
177+
private PunishmentData convertPunishmentToData(Punishment punishment, boolean isActive, Operator pardonOperator, String fromEvent) {
178178
PunishmentData punishmentData = new PunishmentData();
179179
punishmentData.plugin_name = BanWardenPluginType.LIBERTYBANS.name().toLowerCase();
180180
punishmentData.plugin_punishment_id = String.valueOf(punishment.getIdentifier());
@@ -183,6 +183,7 @@ private PunishmentData convertPunishmentToData(Punishment punishment, boolean is
183183
punishmentData.end_at = punishment.getEndDateSeconds() * 1000;
184184
punishmentData.reason = punishment.getReason();
185185
punishmentData.is_active = isActive;
186+
punishmentData.from_event = fromEvent;
186187

187188
// Server scope
188189
if (punishment.getScope().appliesTo("*")) {

common/src/main/java/com/xinecraft/minetrax/common/banwarden/hooks/LitebansHook.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private void registerEventListeners() {
6161
@Override
6262
public void entryAdded(Entry entry) {
6363
try {
64-
PunishmentData data = convertEntryToData(entry, false);
64+
PunishmentData data = convertEntryToData(entry, false, "punish");
6565
ReportPlayerPunishment.reportSync(data);
6666
} catch (Exception e) {
6767
LoggingUtil.error("[BanWarden] EntryAdded -> Error reporting event to Minetrax: " + e.getMessage());
@@ -71,7 +71,7 @@ public void entryAdded(Entry entry) {
7171
@Override
7272
public void entryRemoved(Entry entry) {
7373
try {
74-
PunishmentData data = convertEntryToData(entry, true);
74+
PunishmentData data = convertEntryToData(entry, true, "pardon");
7575
ReportPlayerPunishment.reportSync(data);
7676
} catch (Exception e) {
7777
LoggingUtil.error("[BanWarden] EntryRemoved -> Error reporting event to Minetrax: " + e.getMessage());
@@ -130,15 +130,15 @@ public CompletionStage<Void> apply(Void unused) {
130130
private CompletionStage<List<PunishmentData>> fetchPunishmentChunk(int limit, int offset) {
131131
return CompletableFuture.supplyAsync(() -> {
132132
List<PunishmentData> punishmentDataList = new ArrayList<>();
133-
String sql = "SELECT id, uuid, ip, reason, banned_by_uuid, banned_by_name, removed_by_uuid, removed_by_name, removed_by_reason, removed_by_date, time, until, template, server_scope, server_origin, silent, ipban, ipban_wildcard, active,'ban'as type FROM litebans_bans UNION ALL SELECT id, uuid, ip, reason, banned_by_uuid, banned_by_name, removed_by_uuid, removed_by_name, removed_by_reason, removed_by_date, time, until, template, server_scope, server_origin, silent, ipban, ipban_wildcard, active,'mute'as type FROM litebans_mutes UNION ALL SELECT id, uuid, ip, reason, banned_by_uuid, banned_by_name, removed_by_uuid, removed_by_name, removed_by_reason, removed_by_date, time, until, template, server_scope, server_origin, silent, ipban, ipban_wildcard, active,'warn'as type FROM litebans_warnings ORDER BY id ASC LIMIT ? OFFSET ?";
133+
String sql = "SELECT id, uuid, ip, reason, banned_by_uuid, banned_by_name, removed_by_uuid, removed_by_name, removed_by_reason, removed_by_date, time, until, template, server_scope, server_origin, silent, ipban, ipban_wildcard, active,'ban' as type FROM litebans_bans UNION ALL SELECT id, uuid, ip, reason, banned_by_uuid, banned_by_name, removed_by_uuid, removed_by_name, removed_by_reason, removed_by_date, time, until, template, server_scope, server_origin, silent, ipban, ipban_wildcard, active,'mute' as type FROM litebans_mutes UNION ALL SELECT id, uuid, ip, reason, banned_by_uuid, banned_by_name, removed_by_uuid, removed_by_name, removed_by_reason, removed_by_date, time, until, template, server_scope, server_origin, silent, ipban, ipban_wildcard, active,'warn' as type FROM litebans_warnings ORDER BY TIME ASC, id ASC LIMIT ? OFFSET ?";
134134

135135
try (PreparedStatement stmt = Database.get().prepareStatement(sql)) {
136136
stmt.setInt(1, limit);
137137
stmt.setInt(2, offset);
138138
ResultSet rs = stmt.executeQuery();
139139

140140
while (rs.next()) {
141-
PunishmentData data = convertResultSetToData(rs);
141+
PunishmentData data = convertResultSetToData(rs, "sync");
142142
punishmentDataList.add(data);
143143
}
144144
} catch (SQLException e) {
@@ -149,7 +149,7 @@ private CompletionStage<List<PunishmentData>> fetchPunishmentChunk(int limit, in
149149
});
150150
}
151151

152-
private PunishmentData convertEntryToData(Entry entry, boolean isRemoved) {
152+
private PunishmentData convertEntryToData(Entry entry, boolean isRemoved, String fromEvent) {
153153
String type = getBanWardenPunishmentType(entry.getType()).name().toLowerCase();
154154
PunishmentData punishmentData = new PunishmentData();
155155
punishmentData.plugin_name = BanWardenPluginType.LITEBANS.name().toLowerCase();
@@ -166,6 +166,7 @@ private PunishmentData convertEntryToData(Entry entry, boolean isRemoved) {
166166
punishmentData.is_ipban = entry.isIpban();
167167
punishmentData.creator_uuid = entry.getExecutorUUID();
168168
punishmentData.creator_username = entry.getExecutorName();
169+
punishmentData.from_event = fromEvent;
169170

170171
if (isRemoved) {
171172
punishmentData.removed_at = System.currentTimeMillis();
@@ -177,7 +178,7 @@ private PunishmentData convertEntryToData(Entry entry, boolean isRemoved) {
177178
return punishmentData;
178179
}
179180

180-
private PunishmentData convertResultSetToData(ResultSet rs) throws SQLException {
181+
private PunishmentData convertResultSetToData(ResultSet rs, String fromEvent) throws SQLException {
181182
PunishmentData punishmentData = new PunishmentData();
182183
punishmentData.plugin_name = BanWardenPluginType.LITEBANS.name().toLowerCase();
183184
punishmentData.plugin_punishment_id = rs.getString("id");
@@ -193,8 +194,9 @@ private PunishmentData convertResultSetToData(ResultSet rs) throws SQLException
193194
punishmentData.is_ipban = rs.getBoolean("ipban");
194195
punishmentData.creator_uuid = rs.getString("banned_by_uuid");
195196
punishmentData.creator_username = rs.getString("banned_by_name");
197+
punishmentData.from_event = fromEvent;
196198

197-
if (rs.getTimestamp("removed_by_date") != null) {
199+
if (rs.getTimestamp("removed_by_date") != null && !rs.getBoolean("active") && rs.getString("removed_by_name") != null && !rs.getString("removed_by_name").startsWith("#")) {
198200
punishmentData.removed_at = rs.getTimestamp("removed_by_date").getTime();
199201
punishmentData.remover_uuid = rs.getString("removed_by_uuid");
200202
punishmentData.remover_username = rs.getString("removed_by_name");
@@ -208,7 +210,7 @@ private BanWardenPunishmentType getBanWardenPunishmentType(String type) {
208210
return switch (type.toLowerCase()) {
209211
case "ban" -> BanWardenPunishmentType.BAN;
210212
case "mute" -> BanWardenPunishmentType.MUTE;
211-
case "warning" -> BanWardenPunishmentType.WARN;
213+
case "warning", "warn" -> BanWardenPunishmentType.WARN;
212214
case "kick" -> BanWardenPunishmentType.KICK;
213215
default -> BanWardenPunishmentType.UNKNOWN;
214216
};

common/src/main/java/com/xinecraft/minetrax/common/data/PunishmentData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ public class PunishmentData {
2828
public String remover_username;
2929
public String removed_reason;
3030
public long removed_at;
31+
32+
public String from_event; // punish, pardon, sync
3133
}

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

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
import com.google.gson.Gson;
44
import com.google.gson.GsonBuilder;
55
import com.google.inject.Inject;
6-
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
76
import com.velocitypowered.api.event.Subscribe;
7+
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
88
import com.velocitypowered.api.plugin.Dependency;
99
import com.velocitypowered.api.plugin.Plugin;
1010
import com.velocitypowered.api.plugin.PluginContainer;
1111
import com.velocitypowered.api.plugin.annotation.DataDirectory;
1212
import com.velocitypowered.api.proxy.ProxyServer;
1313
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
1414
import com.xinecraft.minetrax.common.MinetraxCommon;
15-
import com.xinecraft.minetrax.common.interfaces.MinetraxPlugin;
15+
import com.xinecraft.minetrax.common.enums.BanWardenPluginType;
1616
import com.xinecraft.minetrax.common.enums.PlatformType;
17+
import com.xinecraft.minetrax.common.interfaces.MinetraxPlugin;
1718
import com.xinecraft.minetrax.common.utils.LoggingUtil;
1819
import com.xinecraft.minetrax.common.webquery.WebQueryServer;
1920
import com.xinecraft.minetrax.velocity.hooks.skinsrestorer.SkinsRestorerHook;
@@ -39,7 +40,6 @@
3940
import java.io.File;
4041
import java.io.IOException;
4142
import java.nio.file.Path;
42-
import java.util.HashMap;
4343
import java.util.List;
4444
import java.util.Objects;
4545
import java.util.UUID;
@@ -93,24 +93,11 @@ public class MinetraxVelocity implements MinetraxPlugin {
9393
public ConcurrentHashMap<String, String> joinAddressCache = new ConcurrentHashMap<>();
9494
public Boolean hasSkinsRestorer = false;
9595
public Boolean isSkinsRestorerHookEnabled;
96+
public Boolean isBanWardenEnabled = false;
9697
public static final MinecraftChannelIdentifier PLUGIN_MESSAGE_CHANNEL = MinecraftChannelIdentifier.from(MinetraxCommon.PLUGIN_MESSAGE_CHANNEL);
9798

9899
@Subscribe
99100
public void onProxyInitialization(ProxyInitializeEvent event) {
100-
// GSON builder
101-
gson = new GsonBuilder()
102-
.serializeNulls()
103-
.disableHtmlEscaping()
104-
.create();
105-
106-
// Setup Common
107-
common = new MinetraxCommon();
108-
common.setPlugin(this);
109-
common.setPlatformType(PlatformType.VELOCITY);
110-
common.setGson(gson);
111-
common.setLogger(new VelocityLogger(this));
112-
common.setScheduler(new VelocityScheduler(this));
113-
common.setWebQuery(new VelocityWebQuery(this));
114101
plugin = this;
115102

116103
// Load config
@@ -129,6 +116,22 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
129116
return;
130117
}
131118

119+
// GSON builder
120+
gson = new GsonBuilder()
121+
.serializeNulls()
122+
.disableHtmlEscaping()
123+
.create();
124+
125+
// Setup Common
126+
common = new MinetraxCommon();
127+
common.setPlugin(this);
128+
common.setPlatformType(PlatformType.VELOCITY);
129+
common.setGson(gson);
130+
common.setLogger(new VelocityLogger(this));
131+
common.setScheduler(new VelocityScheduler(this));
132+
common.setWebQuery(new VelocityWebQuery(this));
133+
initBanWarden(common);
134+
132135
// init Bstats
133136
initBstats();
134137

@@ -190,6 +193,7 @@ private void initVariables() {
190193
isAllowOnlyWhitelistedCommandsFromWeb = config.getBoolean("allow-only-whitelisted-commands-from-web", false);
191194
whitelistedCommandsFromWeb = config.getStringList("whitelisted-commands-from-web");
192195
isSkinsRestorerHookEnabled = config.getBoolean("enable-skinsrestorer-hook", false);
196+
isBanWardenEnabled = config.getBoolean("enable-banwarden", false);
193197
serverSessionId = UUID.randomUUID().toString();
194198
}
195199

@@ -223,4 +227,25 @@ private Boolean setupSkinsRestorer() {
223227
return false;
224228
}
225229
}
230+
231+
232+
private void initBanWarden(MinetraxCommon common) {
233+
if (!isBanWardenEnabled) {
234+
logger.warn("[BanWarden] BanWarden is disabled in config.yml");
235+
return;
236+
}
237+
238+
// set which ban plugin is enabled.
239+
if (PluginUtil.checkIfPluginEnabled("litebans")) {
240+
common.initBanWarden(BanWardenPluginType.LITEBANS);
241+
} else if (PluginUtil.checkIfPluginEnabled("libertybans")) {
242+
common.initBanWarden(BanWardenPluginType.LIBERTYBANS);
243+
} else if (PluginUtil.checkIfPluginEnabled("advancedban")) {
244+
common.initBanWarden(BanWardenPluginType.ADVANCEDBAN);
245+
} else {
246+
isBanWardenEnabled = false;
247+
logger.warn("[BanWarden] No supported BanWarden plugin found.");
248+
return;
249+
}
250+
}
226251
}

0 commit comments

Comments
 (0)