Skip to content

Commit

Permalink
Add blockglitch warn & replay (#84)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <pabloherrerapalacio@gmail.com>
  • Loading branch information
Pablete1234 authored Jan 13, 2025
1 parent 47f99ec commit 2273af4
Show file tree
Hide file tree
Showing 9 changed files with 519 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public interface CommunityPermissions {

// Sign Logger
String SIGN_LOG_BROADCASTS = ROOT + ".view-sign-logs"; // Access to view when signs are placed
String BLOCK_GLITCH_BROADCASTS =
ROOT + ".view-block-glitch"; // Access to view blockglitch alerts and replays

// Reports
String REPORTS = ROOT + ".reports"; // Access to view report broadcast & report history
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import dev.pgm.community.history.MatchHistoryCommand;
import dev.pgm.community.mobs.MobCommand;
import dev.pgm.community.moderation.commands.BanCommand;
import dev.pgm.community.moderation.commands.BlockGlitchCommand;
import dev.pgm.community.moderation.commands.KickCommand;
import dev.pgm.community.moderation.commands.MuteCommand;
import dev.pgm.community.moderation.commands.PunishmentCommand;
Expand Down Expand Up @@ -137,6 +138,7 @@ protected void registerCommands() {
register(new PunishmentCommand());
register(new ToolCommand());
register(new WarnCommand());
register(new BlockGlitchCommand());

// Mutations
register(new MutationCommands());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class ModerationConfig extends FeatureConfigImpl {
private static final String LOOKUP_SIGN_KEY = TOOLS_KEY + ".lookup-sign";

private static final String SIGN_LOGGER_KEY = KEY + ".sign-logger";
private static final String BLOCK_GLITCH_LOGGER_KEY = KEY + ".block-glitch-logger";

// General options
private boolean persist;
Expand Down Expand Up @@ -92,6 +93,8 @@ public class ModerationConfig extends FeatureConfigImpl {

// Sign Logger
private boolean signLoggerEnabled;
// BlockGlitch Logger
private boolean blockGlitchLoggerEnabled;

/**
* Config options related to {@link ModerationFeature}
Expand Down Expand Up @@ -260,6 +263,10 @@ public boolean isSignLoggerEnabled() {
return signLoggerEnabled;
}

public boolean isBlockGlitchLoggerEnabled() {
return blockGlitchLoggerEnabled;
}

@Override
public void reload(Configuration config) {
super.reload(config);
Expand Down Expand Up @@ -311,5 +318,7 @@ public void reload(Configuration config) {

// Sign Logger
this.signLoggerEnabled = config.getBoolean(getEnabledKey(SIGN_LOGGER_KEY));
// BlockGlitch logger
this.blockGlitchLoggerEnabled = config.getBoolean(getEnabledKey(BLOCK_GLITCH_LOGGER_KEY));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package dev.pgm.community.moderation.commands;

import static net.kyori.adventure.text.Component.text;
import static tc.oc.pgm.util.text.TextException.exception;

import dev.pgm.community.Community;
import dev.pgm.community.CommunityPermissions;
import dev.pgm.community.moderation.feature.loggers.BlockGlitchLogger;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Location;
import tc.oc.pgm.api.player.MatchPlayer;
import tc.oc.pgm.lib.org.incendo.cloud.annotations.Argument;
import tc.oc.pgm.lib.org.incendo.cloud.annotations.Command;
import tc.oc.pgm.lib.org.incendo.cloud.annotations.Permission;

public class BlockGlitchCommand {
private static final int TP_DISTANCE = 15;
private static final int MAX_NO_OBS_DISTANCE = 40;

private final BlockGlitchLogger blockGlitch;

public BlockGlitchCommand() {
this.blockGlitch = Community.get().getFeatures().getModeration().getBlockGlitchLogger();
}

@Command("blockglitch list")
@Permission(CommunityPermissions.BLOCK_GLITCH_BROADCASTS)
public void listIncidents(MatchPlayer player) {
var incidents = blockGlitch.getIncidents();
if (incidents.isEmpty()) throw exception("No recorded blockglitch incidents");

for (var incident : incidents) {
player.sendMessage(incident.getDescription());
}
}

@Command("blockglitch replay <id>")
@Permission(CommunityPermissions.BLOCK_GLITCH_BROADCASTS)
public void replayIncident(MatchPlayer player, @Argument("id") int id) {
var incident = blockGlitch.getIncident(id);
if (incident == null) throw exception("Sorry, the block glitch happened too long ago to view");
Location curr = player.getLocation();
int distance =
(int) Math.min(curr.distance(incident.getStart()), curr.distance(incident.getEnd()));

if (player.isObserving()) {
if (distance > TP_DISTANCE) player.getBukkit().teleport(incident.getStart());
} else if (distance > MAX_NO_OBS_DISTANCE) {
throw exception("Join observers or get closer to watch this replay");
}

player.sendMessage(text("Replaying ", NamedTextColor.GRAY)
.append(incident.getPlayerName())
.append(text(" blockglitching "))
.append(incident.getWhen().color(NamedTextColor.YELLOW)));
incident.play(player.getBukkit());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.pgm.community.moderation.feature;

import dev.pgm.community.feature.Feature;
import dev.pgm.community.moderation.feature.loggers.BlockGlitchLogger;
import dev.pgm.community.moderation.punishments.NetworkPunishment;
import dev.pgm.community.moderation.punishments.Punishment;
import dev.pgm.community.moderation.punishments.PunishmentType;
Expand Down Expand Up @@ -145,4 +146,6 @@ Punishment punish(
String getStaffFormat();

ModerationTools getTools();

BlockGlitchLogger getBlockGlitchLogger();
}
Loading

0 comments on commit 2273af4

Please sign in to comment.