Skip to content

Commit a200939

Browse files
authored
fixed issues
Fixed TempMute Menu – Resolved an issue where, even after selecting duration and reason, the menu continued to prompt for duration selection. Alts Detection – Fixed alt detection system not triggering or functioning as expected. Webhook System – Corrected punishment webhook integration so notifications now properly send to configured endpoints.
1 parent df5afcf commit a200939

File tree

10 files changed

+144
-18
lines changed

10 files changed

+144
-18
lines changed

dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>me.wethink</groupId>
55
<artifactId>WeGuardian</artifactId>
66
<name>WeGuardian</name>
7-
<version>1.1</version>
7+
<version>1.2</version>
88
<build>
99
<resources>
1010
<resource>

pom.xml

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

77
<groupId>me.wethink</groupId>
88
<artifactId>WeGuardian</artifactId>
9-
<version>1.1</version>
9+
<version>1.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>WeGuardian</name>

src/main/java/me/wethink/weGuardian/WeGuardian.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ private void registerCommands() {
214214
getCommand("notesmenu").setTabCompleter(new NotesMenuCommand(this));
215215
getCommand("unbanmenu").setTabCompleter(new UnbanMenuCommand(this));
216216
getCommand("unmutemenu").setTabCompleter(new UnmuteMenuCommand(this));
217+
218+
if (getCommand("weguardian") != null) {
219+
WeGuardianCommand wg = new WeGuardianCommand(this);
220+
getCommand("weguardian").setExecutor(wg);
221+
getCommand("weguardian").setTabCompleter(wg);
222+
}
217223
}
218224

219225
private void registerPlaceholders() {

src/main/java/me/wethink/weGuardian/commands/WeGuardianCommand.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@ private void handleReload(CommandSender sender) {
5050
sender.sendMessage(MessageUtils.colorize("&6⚡ Reloading WeGuardian..."));
5151

5252
try {
53-
plugin.reloadConfig();
53+
plugin.reloadConfigurations();
5454

55-
sender.sendMessage(MessageUtils.colorize("&a✓ Configuration files reloaded successfully"));
55+
plugin.getTemplateService().reloadTemplates();
56+
57+
sender.sendMessage(MessageUtils.colorize("&a✓ Reload complete"));
5658
sender.sendMessage(MessageUtils.colorize("&7 - config.yml"));
5759
sender.sendMessage(MessageUtils.colorize("&7 - messages.yml"));
58-
sender.sendMessage(MessageUtils.colorize("&7 - gui.yml"));
59-
sender.sendMessage(MessageUtils.colorize("&7 - settings.yml"));
60-
60+
sender.sendMessage(MessageUtils.colorize("&7 - gui/*.yml"));
61+
sender.sendMessage(MessageUtils.colorize("&7 - templates.yml"));
6162
} catch (Exception e) {
62-
sender.sendMessage(MessageUtils.colorize("&c✗ Error reloading configuration: " + e.getMessage()));
63+
sender.sendMessage(MessageUtils.colorize("&c✗ Error reloading: " + e.getMessage()));
6364
plugin.getLogger().severe("Error reloading configuration: " + e.getMessage());
6465
}
6566
}

src/main/java/me/wethink/weGuardian/database/YamlDatabaseManager.java

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class YamlDatabaseManager implements DatabaseManager {
2929
private final Map<Integer, Punishment> punishmentCache;
3030
private final Map<UUID, PlayerData> playerDataCache;
3131
private final Map<Integer, BanwaveEntry> banwaveCache;
32+
private final Map<UUID, Map<String, Long>> playerConnectionsCache;
3233
private final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
3334

3435
public YamlDatabaseManager(WeGuardian plugin) {
@@ -39,6 +40,7 @@ public YamlDatabaseManager(WeGuardian plugin) {
3940
this.punishmentCache = new ConcurrentHashMap<>();
4041
this.playerDataCache = new ConcurrentHashMap<>();
4142
this.banwaveCache = new ConcurrentHashMap<>();
43+
this.playerConnectionsCache = new ConcurrentHashMap<>();
4244
this.nextId = new AtomicInteger(1);
4345

4446
if (!dataDir.exists()) {
@@ -95,6 +97,15 @@ private void loadData() {
9597
if (playerData != null) {
9698
playerDataCache.put(playerUuid, playerData);
9799
}
100+
ConfigurationSection connectionsSection = playerConfig.getConfigurationSection("connections");
101+
if (connectionsSection != null) {
102+
Map<String, Long> ipMap = new ConcurrentHashMap<>();
103+
for (String ip : connectionsSection.getKeys(false)) {
104+
long lastSeenTs = connectionsSection.getLong(ip, 0L);
105+
ipMap.put(ip, lastSeenTs);
106+
}
107+
playerConnectionsCache.put(playerUuid, ipMap);
108+
}
98109

99110
ConfigurationSection punishmentsSection = playerConfig.getConfigurationSection("punishments");
100111
if (punishmentsSection != null) {
@@ -311,6 +322,7 @@ public CompletableFuture<Void> savePlayerData(PlayerData playerData) {
311322

312323
YamlConfiguration playerConfig = getPlayerConfig(playerData.getUuid());
313324
serializePlayerData(playerConfig, playerData);
325+
serializePlayerConnections(playerConfig, playerData.getUuid());
314326
savePlayerConfig(playerData.getUuid(), playerConfig);
315327
});
316328
}
@@ -396,6 +408,18 @@ private void serializePlayerData(YamlConfiguration config, PlayerData playerData
396408
config.set("last_ip", playerData.getLastIP());
397409
}
398410

411+
private void serializePlayerConnections(YamlConfiguration config, UUID uuid) {
412+
Map<String, Long> ipMap = playerConnectionsCache.get(uuid);
413+
if (ipMap == null) return;
414+
ConfigurationSection section = config.getConfigurationSection("connections");
415+
if (section == null) {
416+
section = config.createSection("connections");
417+
}
418+
for (Map.Entry<String, Long> entry : ipMap.entrySet()) {
419+
section.set(entry.getKey(), entry.getValue());
420+
}
421+
}
422+
399423
private BanwaveEntry deserializeBanwaveEntry(ConfigurationSection section) {
400424
try {
401425
BanwaveEntry entry = new BanwaveEntry();
@@ -812,17 +836,55 @@ public CompletableFuture<Integer> getTotalPunishments() {
812836

813837
@Override
814838
public CompletableFuture<List<PlayerConnection>> getPlayerConnections(UUID uuid) {
815-
return CompletableFuture.completedFuture(new ArrayList<>());
839+
return CompletableFuture.supplyAsync(() -> {
840+
List<PlayerConnection> list = new ArrayList<>();
841+
Map<String, Long> ipMap = playerConnectionsCache.get(uuid);
842+
if (ipMap == null || ipMap.isEmpty()) return list;
843+
PlayerData data = playerDataCache.get(uuid);
844+
String playerName = data != null ? data.getPlayerName() : "Unknown";
845+
for (Map.Entry<String, Long> e : ipMap.entrySet()) {
846+
LocalDateTime ts = LocalDateTime.ofEpochSecond(e.getValue() / 1000L, 0, java.time.ZoneOffset.UTC);
847+
list.add(new PlayerConnectionImpl(uuid, playerName, e.getKey(), ts));
848+
}
849+
return list;
850+
});
816851
}
817852

818853
@Override
819854
public CompletableFuture<List<PlayerConnection>> getPlayersFromIP(String ip) {
820-
return CompletableFuture.completedFuture(new ArrayList<>());
855+
return CompletableFuture.supplyAsync(() -> {
856+
List<PlayerConnection> list = new ArrayList<>();
857+
for (Map.Entry<UUID, Map<String, Long>> entry : playerConnectionsCache.entrySet()) {
858+
Long tsMillis = entry.getValue().get(ip);
859+
if (tsMillis != null) {
860+
UUID uuid = entry.getKey();
861+
PlayerData data = playerDataCache.get(uuid);
862+
String name = data != null ? data.getPlayerName() : "Unknown";
863+
LocalDateTime ts = LocalDateTime.ofEpochSecond(tsMillis / 1000L, 0, java.time.ZoneOffset.UTC);
864+
list.add(new PlayerConnectionImpl(uuid, name, ip, ts));
865+
}
866+
}
867+
return list;
868+
});
821869
}
822870

823871
@Override
824872
public CompletableFuture<Void> recordPlayerConnection(UUID uuid, String playerName, String ip) {
825-
return CompletableFuture.completedFuture(null);
873+
return CompletableFuture.runAsync(() -> {
874+
Map<String, Long> ipMap = playerConnectionsCache.computeIfAbsent(uuid, k -> new ConcurrentHashMap<>());
875+
long now = System.currentTimeMillis();
876+
ipMap.put(ip, now);
877+
878+
PlayerData data = playerDataCache.computeIfAbsent(uuid, u -> new PlayerData(uuid, playerName));
879+
data.setPlayerName(playerName);
880+
data.setLastIP(ip);
881+
data.setLastJoin(now);
882+
883+
YamlConfiguration playerConfig = getPlayerConfig(uuid);
884+
serializePlayerData(playerConfig, data);
885+
serializePlayerConnections(playerConfig, uuid);
886+
savePlayerConfig(uuid, playerConfig);
887+
});
826888
}
827889

828890
@Override
@@ -833,4 +895,38 @@ public CompletableFuture<List<Punishment>> getAllActivePunishments() {
833895
.collect(Collectors.toList())
834896
);
835897
}
898+
899+
private static class PlayerConnectionImpl implements DatabaseManager.PlayerConnection {
900+
private final UUID uuid;
901+
private final String playerName;
902+
private final String ip;
903+
private final LocalDateTime timestamp;
904+
905+
PlayerConnectionImpl(UUID uuid, String playerName, String ip, LocalDateTime timestamp) {
906+
this.uuid = uuid;
907+
this.playerName = playerName;
908+
this.ip = ip;
909+
this.timestamp = timestamp;
910+
}
911+
912+
@Override
913+
public UUID getUuid() {
914+
return uuid;
915+
}
916+
917+
@Override
918+
public String getPlayerName() {
919+
return playerName;
920+
}
921+
922+
@Override
923+
public String getIp() {
924+
return ip;
925+
}
926+
927+
@Override
928+
public LocalDateTime getTimestamp() {
929+
return timestamp;
930+
}
931+
}
836932
}

src/main/java/me/wethink/weGuardian/gui/MenuHandler.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public abstract class MenuHandler {
2323
protected final String menuType;
2424
protected final Map<Player, String> targetPlayers = new HashMap<>();
2525
protected final Map<Player, Map<String, Object>> selectedData = new HashMap<>();
26+
private final java.util.Set<Player> preserveOnClose = new java.util.HashSet<>();
2627
protected MenuManager menuManager;
2728

2829
public MenuHandler(WeGuardian plugin, String menuType) {
@@ -137,7 +138,11 @@ private boolean isSlotMatch(ConfigurationSection itemConfig, int slot) {
137138

138139
public void cleanupPlayer(Player player) {
139140
targetPlayers.remove(player);
140-
selectedData.remove(player);
141+
if (preserveOnClose.contains(player)) {
142+
preserveOnClose.remove(player);
143+
} else {
144+
selectedData.remove(player);
145+
}
141146
onMenuClose(player);
142147
}
143148

@@ -165,6 +170,10 @@ protected void clearSelectedData(Player player) {
165170
selectedData.remove(player);
166171
}
167172

173+
protected void preserveSelectionOnNextClose(Player player) {
174+
preserveOnClose.add(player);
175+
}
176+
168177
protected abstract ConfigurationSection getMenuConfig();
169178

170179
protected abstract void handleItemClick(Player staff, String targetPlayer, String itemKey, ConfigurationSection itemConfig);

src/main/java/me/wethink/weGuardian/gui/menus/TempmuteMenu.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import me.wethink.weGuardian.WeGuardian;
44
import me.wethink.weGuardian.gui.MenuHandler;
5-
import me.wethink.weGuardian.gui.menus.MenuManager;
65
import me.wethink.weGuardian.utils.MessageUtils;
76
import org.bukkit.configuration.ConfigurationSection;
87
import org.bukkit.entity.Player;
@@ -40,15 +39,14 @@ protected void handleItemClick(Player staff, String targetPlayer, String itemKey
4039
Map<String, Object> selectedData = getSelectedData(staff);
4140
selectedData.put("selectedDuration", duration);
4241
staff.sendMessage(MessageUtils.colorize("&eSelected duration: &f" + duration));
43-
42+
preserveSelectionOnNextClose(staff);
4443
refreshInventory(staff, targetPlayer);
4544
return;
4645
}
4746

4847
if (action.startsWith("execute_punishment:")) {
4948
String[] parts = action.split(":", 4);
5049
if (parts.length >= 4) {
51-
String punishmentType = parts[1];
5250
String reason = parts[2];
5351
String duration = parts[3];
5452

@@ -117,6 +115,7 @@ protected void handleItemClick(Player staff, String targetPlayer, String itemKey
117115
String duration = itemConfig.getString("duration", "30m");
118116
selectedData.put("selectedDuration", duration);
119117
staff.sendMessage(MessageUtils.colorize("&eSelected duration: &f" + duration));
118+
preserveSelectionOnNextClose(staff);
120119
refreshInventory(staff, targetPlayer);
121120
return;
122121
}

src/main/java/me/wethink/weGuardian/services/PunishmentService.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.concurrent.ScheduledExecutorService;
2626
import java.util.concurrent.TimeUnit;
2727
import java.util.concurrent.atomic.AtomicInteger;
28+
import me.wethink.weGuardian.services.DiscordWebhookService;
2829

2930
public class PunishmentService {
3031

@@ -211,6 +212,8 @@ PunishmentType.TEMPBAN, reason, expiresAt, getServerName()
211212
}
212213

213214
plugin.getNotificationService().broadcastPunishment(punishment);
215+
var webhook = new DiscordWebhookService(plugin);
216+
webhook.sendPunishmentWebhook(punishment);
214217
return CompletableFuture.completedFuture(true);
215218
}
216219
return CompletableFuture.completedFuture(false);
@@ -253,6 +256,8 @@ PunishmentType.MUTE, reason, null, getServerName()
253256
}
254257

255258
plugin.getNotificationService().broadcastPunishment(punishment);
259+
var webhook = new DiscordWebhookService(plugin);
260+
webhook.sendPunishmentWebhook(punishment);
256261
return CompletableFuture.completedFuture(true);
257262
}
258263
return CompletableFuture.completedFuture(false);
@@ -300,6 +305,8 @@ PunishmentType.TEMPMUTE, reason, expiresAt, getServerName()
300305
}
301306

302307
plugin.getNotificationService().broadcastPunishment(punishment);
308+
var webhook = new DiscordWebhookService(plugin);
309+
webhook.sendPunishmentWebhook(punishment);
303310
return CompletableFuture.completedFuture(true);
304311
}
305312
return CompletableFuture.completedFuture(false);
@@ -336,6 +343,8 @@ PunishmentType.KICK, reason, null, getServerName()
336343
}
337344

338345
plugin.getNotificationService().broadcastPunishment(punishment);
346+
var webhook = new DiscordWebhookService(plugin);
347+
webhook.sendPunishmentWebhook(punishment);
339348
return CompletableFuture.completedFuture(true);
340349
}
341350
return CompletableFuture.completedFuture(false);
@@ -368,6 +377,8 @@ PunishmentType.WARN, reason, null, getServerName()
368377
}
369378

370379
plugin.getNotificationService().broadcastPunishment(punishment);
380+
var webhook = new DiscordWebhookService(plugin);
381+
webhook.sendPunishmentWebhook(punishment);
371382
return CompletableFuture.completedFuture(true);
372383
}
373384
return CompletableFuture.completedFuture(false);
@@ -398,6 +409,8 @@ public CompletableFuture<Boolean> unban(String targetName, String staffName) {
398409
banCache.remove(targetUuid);
399410
}
400411
plugin.getNotificationService().broadcastUnpunishment(banPunishment, staffName);
412+
var webhook = new DiscordWebhookService(plugin);
413+
webhook.sendUnpunishmentWebhook(banPunishment, staffName);
401414
return true;
402415
});
403416
});
@@ -426,6 +439,8 @@ public CompletableFuture<Boolean> unmute(String targetName, String staffName) {
426439
muteCache.remove(targetUuid);
427440
}
428441
plugin.getNotificationService().broadcastUnpunishment(mutePunishment, staffName);
442+
var webhook = new DiscordWebhookService(plugin);
443+
webhook.sendUnpunishmentWebhook(mutePunishment, staffName);
429444
return true;
430445
});
431446
});

src/main/resources/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ console_commands:
8484
- "broadcast &a{player} has been unmuted by {staff}"
8585

8686
discord:
87-
enabled: false
88-
webhook_url: "https://discord.com/api/webhooks/YOUR_WEBHOOK_URL"
87+
enabled: true
88+
webhook_url: "https://discord.com/api/webhooks/REPLACE_WITH_YOUR_WEBHOOK"
8989
username: "WeGuardian"
9090
avatar_url: "https://i.imgur.com/your-avatar.png"
9191
embed_color: 16711680

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: WeGuardian
2-
version: '1.1'
2+
version: '1.2'
33
main: me.wethink.weGuardian.WeGuardian
44
api-version: '1.21'
55
load: STARTUP

0 commit comments

Comments
 (0)