Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -16,6 +16,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -178,6 +179,13 @@ public class Report extends Appliance {
|
||||
issuer.sendMessage(component.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new ReportCreatedListener()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected List<ApplianceCommand<?>> commands() {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.core.event.ReportCreatedEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
public class ReportCreatedListener extends ApplianceListener<Report> {
|
||||
@EventHandler
|
||||
public void onReport(ReportCreatedEvent event) {
|
||||
OfflinePlayer reporter = Bukkit.getOfflinePlayer(event.getReport().reporter());
|
||||
OfflinePlayer reported = Bukkit.getOfflinePlayer(event.getReport().reported());
|
||||
|
||||
Component message = Component.text(
|
||||
"\uD83D\uDD14 Neuer Report von %s gegen %s: %s".formatted(reporter.getName(), reported.getName(), event.getReport().reason()),
|
||||
NamedTextColor.YELLOW
|
||||
);
|
||||
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(player -> player.hasPermission("admin"))
|
||||
.forEach(player -> player.sendMessage(message));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiIllegalSignCharacters;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AntiIllegalSignCharacters extends Appliance {
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new SignEditListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiIllegalSignCharacters;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
|
||||
import java.text.Normalizer;
|
||||
import java.util.Set;
|
||||
|
||||
class SignEditListener extends ApplianceListener<AntiIllegalSignCharacters> {
|
||||
private static final Set<Integer> ALLOWED_CHARS = Set.of(
|
||||
(int)' ', (int)'.', (int)',', (int)';', (int)':', (int)'!', (int)'?',
|
||||
(int)'"', (int)'\'',
|
||||
(int)'(', (int)')', (int)'[', (int)']', (int)'{', (int)'}',
|
||||
(int)'-', (int)'_', (int)'+', (int)'=', (int)'/', (int)'\\',
|
||||
(int)'@', (int)'#', (int)'$', (int)'%', (int)'&', (int)'*',
|
||||
(int)'<', (int)'>', (int)'|',
|
||||
(int)'~', (int)'`', (int)'^'
|
||||
);
|
||||
|
||||
private static final Set<Integer> ALLOWED_EXTRA = Set.of(
|
||||
(int)'Ä', (int)'Ö', (int)'Ü', (int)'ä', (int)'ö', (int)'ü', (int)'ß',
|
||||
(int)'€', (int)'°', (int)'µ'
|
||||
);
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onSignEdit(SignChangeEvent event) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Component line = event.line(i);
|
||||
if (line == null) continue;
|
||||
String plainString = PlainTextComponentSerializer.plainText().serialize(line);
|
||||
plainString = Normalizer.normalize(plainString, Normalizer.Form.NFC);
|
||||
String cleaned = filterAllowed(plainString);
|
||||
event.line(i, Component.text(cleaned));
|
||||
}
|
||||
}
|
||||
|
||||
private static String filterAllowed(String s) {
|
||||
StringBuilder out = new StringBuilder(s.length());
|
||||
|
||||
for (int off = 0; off < s.length(); ) {
|
||||
int cp = s.codePointAt(off);
|
||||
off += Character.charCount(cp);
|
||||
|
||||
if (isForbidden(cp)) continue;
|
||||
|
||||
if (Character.isLetterOrDigit(cp)) {
|
||||
out.appendCodePoint(cp);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ALLOWED_CHARS.contains(cp) || ALLOWED_EXTRA.contains(cp)) {
|
||||
out.appendCodePoint(cp);
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
private static boolean isForbidden(int cp) {
|
||||
// Surrogates / invalid
|
||||
if (cp >= 0xD800 && cp <= 0xDFFF) return true;
|
||||
|
||||
// Private Use Area (Mod/Pack-Icons/Placeholder)
|
||||
if (cp >= 0xE000 && cp <= 0xF8FF) return true;
|
||||
|
||||
// Zero-width and control characters
|
||||
if (cp == 0x200B || cp == 0x200C || cp == 0x200D || cp == 0xFEFF) return true;
|
||||
|
||||
// BiDi-Steuerzeichen
|
||||
if (cp >= 0x202A && cp <= 0x202E) return true;
|
||||
if (cp >= 0x2066 && cp <= 0x2069) return true;
|
||||
|
||||
return cp == '§';
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Appliance.Flags(enabled = false)
|
||||
public class AntiInventoryMove extends Appliance {
|
||||
private static final long errorTimeMargin = Ticks.SINGLE_TICK_DURATION_MS * 2;
|
||||
|
||||
|
||||
@@ -3,13 +3,15 @@ package eu.mhsl.craftattack.spawn.common.appliances.security.antiInventoryMove;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
|
||||
class InventoryTrackerListener extends ApplianceListener<AntiInventoryMove> {
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onOpen(InventoryOpenEvent event) {
|
||||
if(!(event.getPlayer() instanceof Player player)) return;
|
||||
if(event.isCancelled()) return;
|
||||
this.getAppliance().setInvOpen(player, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,14 +28,16 @@ public class WebsiteHook extends HttpHook {
|
||||
return HttpServer.nothing;
|
||||
}));
|
||||
|
||||
record CreatedReport(String reporter, String reported, String reason) {}
|
||||
record CreatedReport(UUID reporter, UUID reported, String reason) {}
|
||||
this.addAction("report", new JsonAction<>(CreatedReport.class, createdReport -> {
|
||||
Main.logger().info(String.format("New Report from Hook: (%s) Reporter: %s Reported: %s", createdReport.reason, createdReport.reporter, createdReport.reported));
|
||||
SpawnEvent.call(new ReportCreatedEvent(new ReportCreatedEvent.CreatedReport(createdReport.reporter, createdReport.reported, createdReport.reason)));
|
||||
return HttpServer.nothing;
|
||||
}));
|
||||
|
||||
record CreatedStrike(UUID uuid) {}
|
||||
this.addAction("strike", new JsonAction<>(CreatedStrike.class, createdStrike -> {
|
||||
Main.logger().info(String.format("New Strike from Hook! (User %s)", createdStrike.uuid));
|
||||
SpawnEvent.call(new StrikeCreatedEvent(new StrikeCreatedEvent.CreatedStrike(createdStrike.uuid)));
|
||||
return HttpServer.nothing;
|
||||
}));
|
||||
|
||||
@@ -4,6 +4,8 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ReportCreatedEvent extends Event {
|
||||
private static final HandlerList HANDLERS = new HandlerList();
|
||||
@Override
|
||||
@@ -15,7 +17,7 @@ public class ReportCreatedEvent extends Event {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public record CreatedReport(String reporter, String reported, String reason) {}
|
||||
public record CreatedReport(UUID reporter, UUID reported, String reason) {}
|
||||
|
||||
private final CreatedReport report;
|
||||
public ReportCreatedEvent(CreatedReport report) {
|
||||
|
||||
Reference in New Issue
Block a user