Skip to content

Commit

Permalink
Allow AutoKiller to be disabled
Browse files Browse the repository at this point in the history
Signed-off-by: applenick <[email protected]>
  • Loading branch information
applenick committed Mar 11, 2024
1 parent 067eaae commit a6b10df
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/main/java/tc/oc/occ/cheaty/BotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class BotConfig {

private boolean reportsEnabled;
private boolean relayCommandEnabled;
private boolean autoKillerEnabled;

private String reportFormat;
private String relayFormat;
Expand Down Expand Up @@ -56,6 +57,7 @@ public void reload(Configuration config) {

this.reportsEnabled = config.getBoolean("types.reports");
this.relayCommandEnabled = config.getBoolean("types.relay-command");
this.autoKillerEnabled = config.getBoolean("types.auto-killer");

this.reportFormat = config.getString("report-format");
this.relayFormat = config.getString("relay-format");
Expand Down Expand Up @@ -107,6 +109,10 @@ public boolean isRelayCommandEnabled() {
return relayCommandEnabled;
}

public boolean isAutoKillerEnabled() {
return autoKillerEnabled;
}

public String getReportFormat() {
return replaceServerName(reportFormat);
}
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/tc/oc/occ/cheaty/BotListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
import net.climaxmc.autokiller.events.AutoKillCheatEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import tc.oc.occ.cheaty.DiscordBot.RelayType;

public class BotListener implements Listener {

private final DiscordBot bot;
private final BotConfig config;

public BotListener(DiscordBot bot, BotConfig config) {
public BotListener(DiscordBot bot) {
this.bot = bot;
this.config = config;
}

@EventHandler
Expand All @@ -23,6 +20,6 @@ public void onPlayerReport(PlayerReportEvent event) {

@EventHandler
public void onAutoKillerViolation(AutoKillCheatEvent event) {
bot.sendRelay(event.getAlert(), RelayType.AUTOKILL);
bot.sendAutoKiller(event);
}
}
2 changes: 1 addition & 1 deletion src/main/java/tc/oc/occ/cheaty/Cheaty.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void setupCommands() {
}

private void registerListeners() {
this.getServer().getPluginManager().registerEvents(new BotListener(bot, config), this);
this.getServer().getPluginManager().registerEvents(new BotListener(bot), this);
}

public void reloadBotConfig() {
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/tc/oc/occ/cheaty/DiscordBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.UUID;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import net.climaxmc.autokiller.events.AutoKillCheatEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -89,6 +90,11 @@ private Optional<ServerChannel> getChannel(String id) {
return Optional.empty();
}

private String getUsername(UUID playerId) {
Player player = Bukkit.getPlayer(playerId);
return player != null ? player.getName() : null;
}

private void sendMessage(String message, boolean report) {
if (api != null) {
api.getServerById(config.getDiscordServerId())
Expand Down Expand Up @@ -129,17 +135,18 @@ public void sendReport(PlayerReportEvent event) {
}
}

private String getUsername(UUID playerId) {
Player player = Bukkit.getPlayer(playerId);
return player != null ? player.getName() : null;
}

public void sendRelay(String message, RelayType type) {
if (!config.isRelayCommandEnabled()) return;
String formatted = config.getRelayFormat().replace("%message%", message);
sendMessage(getPrefix(type) + formatted, false);
}

public void sendAutoKiller(AutoKillCheatEvent event) {
if (!config.isAutoKillerEnabled()) return;
String formatted = config.getRelayFormat().replace("%message%", event.getAlert());
sendMessage(getPrefix(RelayType.AUTOKILL) + formatted, false);
}

public void sendReportPing(Report report, int numReports) {
List<String> pingRoles = config.getDiscordPingRoles();

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ channels:
types:
reports: true
relay-command: true
auto-killer: true

# Reports (Sent from PGM)
#
Expand Down

0 comments on commit a6b10df

Please sign in to comment.