Skip to content

Commit

Permalink
implement alert manage api
Browse files Browse the repository at this point in the history
  • Loading branch information
AoElite committed Aug 17, 2024
1 parent 39605b7 commit f34703f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {
implementation("it.unimi.dsi:fastutil:8.5.13")
implementation("github.scarsz:configuralize:1.4.0")

implementation("com.github.grimanticheat:grimapi:f10e6fd1b0")
implementation("com.github.grimanticheat:grimapi:f3c5eed2e7")
// Used for local testing: implementation("ac.grim.grimac:grimapi:1.0")

implementation("org.jetbrains:annotations:24.1.0")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ac/grim/grimac/GrimAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public enum GrimAPI {
INSTANCE;

private final AlertManager alertManager = new AlertManager();
private final AlertManagerImpl alertManager = new AlertManagerImpl();
private final SpectateManager spectateManager = new SpectateManager();
private final DiscordManager discordManager = new DiscordManager();
private final PlayerDataManager playerDataManager = new PlayerDataManager();
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/ac/grim/grimac/GrimExternalAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import ac.grim.grimac.api.AbstractCheck;
import ac.grim.grimac.api.GrimAbstractAPI;
import ac.grim.grimac.api.GrimUser;
import ac.grim.grimac.api.alerts.AlertManager;
import ac.grim.grimac.manager.init.Initable;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
Expand Down Expand Up @@ -99,6 +100,11 @@ public void reload() {
GrimAPI.INSTANCE.getExternalAPI().start();
}

@Override
public AlertManager getAlertManager() {
return GrimAPI.INSTANCE.getAlertManager();
}

@Override
public void start() {
variableReplacements.put("%player%", GrimUser::getName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import ac.grim.grimac.GrimAPI;
import ac.grim.grimac.utils.anticheat.LogUtil;
import ac.grim.grimac.utils.anticheat.MessageUtil;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketListenerAbstract;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ac.grim.grimac.manager;

import ac.grim.grimac.GrimAPI;
import ac.grim.grimac.api.alerts.AlertManager;
import ac.grim.grimac.utils.anticheat.MessageUtil;
import lombok.Getter;
import org.bukkit.entity.Player;
Expand All @@ -9,13 +10,18 @@
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;

public class AlertManager {
public class AlertManagerImpl implements AlertManager {
@Getter
private final Set<Player> enabledAlerts = new CopyOnWriteArraySet<>(new HashSet<>());
@Getter
private final Set<Player> enabledVerbose = new CopyOnWriteArraySet<>(new HashSet<>());

@Override
public boolean hasAlertsEnabled(Player player) {
return enabledAlerts.contains(player);
}

@Override
public void toggleAlerts(Player player) {
if (!enabledAlerts.remove(player)) {
String alertString = GrimAPI.INSTANCE.getConfigManager().getConfig().getStringElse("alerts-enabled", "%prefix% &fAlerts enabled");
Expand Down

0 comments on commit f34703f

Please sign in to comment.