Merge branch 'master' into develop-bloodmoon
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation project(':core')
|
implementation project(':core')
|
||||||
|
|
||||||
compileOnly 'io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT'
|
compileOnly 'io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT'
|
||||||
compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT'
|
compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT'
|
||||||
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
||||||
implementation 'com.sparkjava:spark-core:2.9.4'
|
implementation 'com.sparkjava:spark-core:2.9.4'
|
||||||
|
|||||||
@@ -11,15 +11,14 @@ public class CraftAttackReportRepository extends ReportRepository {
|
|||||||
|
|
||||||
public ReqResp<PlayerReports> queryReports(UUID player) {
|
public ReqResp<PlayerReports> queryReports(UUID player) {
|
||||||
return this.get(
|
return this.get(
|
||||||
"report",
|
"users/%s/reports".formatted(player.toString()),
|
||||||
(parameters) -> parameters.addParameter("uuid", player.toString()),
|
|
||||||
PlayerReports.class
|
PlayerReports.class
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReqResp<ReportUrl> createReport(ReportCreationInfo data) {
|
public ReqResp<ReportUrl> createReport(ReportCreationInfo data) {
|
||||||
return this.post(
|
return this.post(
|
||||||
"report",
|
"reports",
|
||||||
data,
|
data,
|
||||||
ReportUrl.class
|
ReportUrl.class
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -23,19 +23,18 @@ public abstract class ReportRepository extends HttpRepository {
|
|||||||
|
|
||||||
public record PlayerReports(
|
public record PlayerReports(
|
||||||
List<Report> from_self,
|
List<Report> from_self,
|
||||||
Object to_self
|
List<Report> to_self
|
||||||
) {
|
) {
|
||||||
public record Report(
|
public record Report(
|
||||||
@Nullable Reporter reported,
|
@Nullable UUID reported,
|
||||||
@NotNull String subject,
|
@NotNull String reason,
|
||||||
boolean draft,
|
@Nullable Long created,
|
||||||
@NotNull String status,
|
@Nullable Status status,
|
||||||
@NotNull String url
|
@NotNull String url
|
||||||
) {
|
) {
|
||||||
public record Reporter(
|
public enum Status {
|
||||||
@NotNull String username,
|
open,
|
||||||
@NotNull String uuid
|
closed,
|
||||||
) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,4 @@ public class InfoBarSetting extends MultiBoolSetting<InfoBarSetting.InfoBarConfi
|
|||||||
public Class<?> dataType() {
|
public Class<?> dataType() {
|
||||||
return InfoBarConfiguration.class;
|
return InfoBarConfiguration.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,18 @@
|
|||||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars;
|
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars;
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
||||||
import eu.mhsl.craftattack.spawn.core.Main;
|
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.MsptBar;
|
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.MsptBar;
|
||||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.PlayerCounterBar;
|
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.PlayerCounterBar;
|
||||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.TpsBar;
|
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.TpsBar;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.persistence.PersistentDataContainer;
|
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class InfoBars extends Appliance {
|
public class InfoBars extends Appliance {
|
||||||
private final NamespacedKey infoBarKey = new NamespacedKey(Main.instance(), "infobars");
|
|
||||||
private final List<Bar> infoBars = List.of(
|
private final List<Bar> infoBars = List.of(
|
||||||
new TpsBar(),
|
new TpsBar(),
|
||||||
new MsptBar(),
|
new MsptBar(),
|
||||||
@@ -27,41 +20,19 @@ public class InfoBars extends Appliance {
|
|||||||
);
|
);
|
||||||
|
|
||||||
public void showAllEnabled(Player player) {
|
public void showAllEnabled(Player player) {
|
||||||
this.getEnabledBars(player).forEach(bar -> this.show(player, bar));
|
InfoBarSetting.InfoBarConfiguration config = Settings.instance().getSetting(player, Settings.Key.InfoBars, InfoBarSetting.InfoBarConfiguration.class);
|
||||||
|
this.setVisible(player, MsptBar.name, config.mspt());
|
||||||
|
this.setVisible(player, PlayerCounterBar.name, config.playerCounter());
|
||||||
|
this.setVisible(player, TpsBar.name, config.tps());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideAllEnabled(Player player) {
|
public void setVisible(Player player, String bar, boolean visible) {
|
||||||
this.getEnabledBars(player).forEach(bar -> this.hide(player, bar));
|
|
||||||
this.setEnabledBars(player, List.of());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void show(Player player, String bar) {
|
|
||||||
this.validateBarName(bar);
|
this.validateBarName(bar);
|
||||||
List<String> existingBars = new ArrayList<>(this.getEnabledBars(player));
|
if(visible) {
|
||||||
existingBars.add(bar);
|
|
||||||
player.showBossBar(this.getBarByName(bar).getBossBar());
|
player.showBossBar(this.getBarByName(bar).getBossBar());
|
||||||
this.setEnabledBars(player, existingBars);
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
public void hide(Player player, String bar) {
|
|
||||||
this.validateBarName(bar);
|
|
||||||
List<String> existingBars = new ArrayList<>(this.getEnabledBars(player));
|
|
||||||
existingBars.remove(bar);
|
|
||||||
player.hideBossBar(this.getBarByName(bar).getBossBar());
|
player.hideBossBar(this.getBarByName(bar).getBossBar());
|
||||||
this.setEnabledBars(player, existingBars);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getEnabledBars(Player player) {
|
|
||||||
PersistentDataContainer container = player.getPersistentDataContainer();
|
|
||||||
if(!container.has(this.infoBarKey)) return List.of();
|
|
||||||
return container.get(this.infoBarKey, PersistentDataType.LIST.strings());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setEnabledBars(Player player, List<String> bars) {
|
|
||||||
Bukkit.getScheduler().runTask(
|
|
||||||
Main.instance(),
|
|
||||||
() -> player.getPersistentDataContainer().set(this.infoBarKey, PersistentDataType.LIST.strings(), bars)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bar getBarByName(String name) {
|
private Bar getBarByName(String name) {
|
||||||
@@ -79,13 +50,7 @@ public class InfoBars extends Appliance {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
Settings.instance().declareSetting(InfoBarSetting.class);
|
Settings.instance().declareSetting(InfoBarSetting.class);
|
||||||
Settings.instance().addChangeListener(InfoBarSetting.class, player -> {
|
Settings.instance().addChangeListener(InfoBarSetting.class, this::showAllEnabled);
|
||||||
this.hideAllEnabled(player);
|
|
||||||
InfoBarSetting.InfoBarConfiguration config = Settings.instance().getSetting(player, Settings.Key.InfoBars, InfoBarSetting.InfoBarConfiguration.class);
|
|
||||||
if(config.mspt()) this.show(player, MsptBar.name);
|
|
||||||
if(config.playerCounter()) this.show(player, PlayerCounterBar.name);
|
|
||||||
if(config.tps()) this.show(player, TpsBar.name);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
|||||||
import eu.mhsl.craftattack.spawn.common.api.repositories.CraftAttackReportRepository;
|
import eu.mhsl.craftattack.spawn.common.api.repositories.CraftAttackReportRepository;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.util.text.ComponentUtil;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.ComponentBuilder;
|
import net.kyori.adventure.text.ComponentBuilder;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
@@ -19,7 +20,9 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class Report extends Appliance {
|
public class Report extends Appliance {
|
||||||
public static Component helpText() {
|
public static Component helpText() {
|
||||||
@@ -78,7 +81,7 @@ public class Report extends Appliance {
|
|||||||
.appendNewline()
|
.appendNewline()
|
||||||
.append(
|
.append(
|
||||||
Component
|
Component
|
||||||
.text(createdReport.data().url(), NamedTextColor.GRAY) // URL mit Weltkugel-Emoji
|
.text(createdReport.data().url(), NamedTextColor.GRAY)
|
||||||
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, createdReport.data().url()))
|
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, createdReport.data().url()))
|
||||||
)
|
)
|
||||||
.appendNewline()
|
.appendNewline()
|
||||||
@@ -128,43 +131,50 @@ public class Report extends Appliance {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ReportRepository.PlayerReports.Report> reports = userReports
|
Function<List<ReportRepository.PlayerReports.Report>, List<ReportRepository.PlayerReports.Report>> filterClosed = reports -> reports.stream()
|
||||||
.data()
|
.filter(report -> Objects.equals(report.status(), ReportRepository.PlayerReports.Report.Status.closed))
|
||||||
.from_self()
|
.toList();
|
||||||
.stream()
|
|
||||||
.filter(report -> !report.draft())
|
|
||||||
.toList()
|
|
||||||
.reversed();
|
|
||||||
|
|
||||||
if(reports.isEmpty()) {
|
List<ReportRepository.PlayerReports.Report> reportsToOthers = filterClosed.apply(userReports.data().from_self()).reversed();
|
||||||
issuer.sendMessage(
|
List<ReportRepository.PlayerReports.Report> reportsToSelf = filterClosed.apply(userReports.data().to_self()).reversed();
|
||||||
Component.text()
|
|
||||||
.append(Component.text("Du hast noch niemanden reportet.", NamedTextColor.RED))
|
|
||||||
.appendNewline()
|
|
||||||
.append(Component.text("Um jemanden zu melden, nutze /report", NamedTextColor.GRAY))
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ComponentBuilder<TextComponent, TextComponent.Builder> component = Component.text()
|
ComponentBuilder<TextComponent, TextComponent.Builder> component = Component.text()
|
||||||
.append(Component.newline())
|
.append(Component.text(
|
||||||
.append(Component.text("Von dir erstellte Reports: ", NamedTextColor.GOLD))
|
!reportsToSelf.isEmpty()
|
||||||
.appendNewline();
|
? "Du wurdest insgesamt %d mal von anderen Spielern gemeldet.".formatted(reportsToSelf.size())
|
||||||
|
: "Du wurdest von keinem anderen Spieler gemeldet.",
|
||||||
|
NamedTextColor.GOLD)
|
||||||
|
);
|
||||||
|
|
||||||
reports.forEach(report -> {
|
|
||||||
component
|
|
||||||
.append(Component.text(" - ", NamedTextColor.WHITE))
|
|
||||||
.append(
|
|
||||||
report.reported() != null
|
|
||||||
? Component.text(report.reported().username(), NamedTextColor.WHITE)
|
|
||||||
: Component.text("Unbekannt", NamedTextColor.YELLOW)
|
|
||||||
)
|
|
||||||
.append(Component.text(String.format(": %s", report.subject()), NamedTextColor.GRAY))
|
|
||||||
.clickEvent(ClickEvent.openUrl(report.url()))
|
|
||||||
.hoverEvent(HoverEvent.showText(Component.text("Klicke, um den Report einzusehen.", NamedTextColor.GOLD)));
|
|
||||||
component.appendNewline();
|
component.appendNewline();
|
||||||
|
|
||||||
|
component.append(Component.text("Von dir erstellte Reports: ", NamedTextColor.GOLD));
|
||||||
|
reportsToOthers.forEach(report -> {
|
||||||
|
Component button = Component.text("[\uD83D\uDC41/\uD83D\uDD8A]")
|
||||||
|
.clickEvent(ClickEvent.openUrl(report.url()))
|
||||||
|
.hoverEvent(HoverEvent.showText(ComponentUtil.clickLink(report.url())));
|
||||||
|
|
||||||
|
Component reportedDisplayName = report.reported() != null
|
||||||
|
? Component.text(Optional.ofNullable(Bukkit.getOfflinePlayer(report.reported()).getName()).orElse(report.reported().toString()), NamedTextColor.WHITE)
|
||||||
|
: Component.text("Unbekannt", NamedTextColor.YELLOW);
|
||||||
|
|
||||||
|
component
|
||||||
|
.appendNewline()
|
||||||
|
.append(Component.text(" \u27A1 ", NamedTextColor.GRAY))
|
||||||
|
.append(button)
|
||||||
|
.append(Component.text(" du gegen ", NamedTextColor.GRAY))
|
||||||
|
.append(reportedDisplayName)
|
||||||
|
.append(Component.text(String.format(": %s", report.reason()), NamedTextColor.GRAY));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(reportsToOthers.isEmpty()) {
|
||||||
|
component
|
||||||
|
.appendNewline()
|
||||||
|
.append(Component.text("Du hast noch niemanden reportet.", NamedTextColor.RED))
|
||||||
|
.appendNewline()
|
||||||
|
.append(Component.text("Um jemanden zu melden, nutze /report", NamedTextColor.GRAY));
|
||||||
|
}
|
||||||
|
|
||||||
issuer.sendMessage(component.build());
|
issuer.sendMessage(component.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class SettingsShortcutSetting extends BoolSetting implements CategorizedS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean defaultValue() {
|
protected Boolean defaultValue() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.common.appliances.security.antiBoatFreecam;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.common.appliances.tooling.acInform.AcInform;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Boat;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class AntiBoatFreecam extends Appliance {
|
||||||
|
private static final float MAX_YAW_OFFSET = 106.0f;
|
||||||
|
private final Map<Player, Float> violatedPlayers = new HashMap<>();
|
||||||
|
|
||||||
|
public AntiBoatFreecam() {
|
||||||
|
Bukkit.getScheduler().runTaskTimerAsynchronously(
|
||||||
|
Main.instance(),
|
||||||
|
() -> Bukkit.getOnlinePlayers().forEach(player -> {
|
||||||
|
if(!(player.getVehicle() instanceof Boat boat)) return;
|
||||||
|
if(!boat.getPassengers().getFirst().equals(player)) return;
|
||||||
|
float playerYaw = player.getYaw();
|
||||||
|
float boatYaw = boat.getYaw();
|
||||||
|
|
||||||
|
float yawDelta = wrapDegrees(playerYaw - boatYaw);
|
||||||
|
if(Math.abs(yawDelta) <= MAX_YAW_OFFSET) return;
|
||||||
|
|
||||||
|
this.violatedPlayers.merge(player, 1f, Float::sum);
|
||||||
|
float violationCount = this.violatedPlayers.get(player);
|
||||||
|
if(violationCount != 1 && violationCount % 100 != 0) return;
|
||||||
|
Main.instance().getAppliance(AcInform.class).notifyAdmins(
|
||||||
|
"internal",
|
||||||
|
player.getName(),
|
||||||
|
"illegalBoatLookYaw",
|
||||||
|
violationCount
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
1L,
|
||||||
|
1L
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float wrapDegrees(float deg) {
|
||||||
|
deg = deg % 360f;
|
||||||
|
if (deg >= 180f) deg -= 360f;
|
||||||
|
if (deg < -180f) deg += 360f;
|
||||||
|
return deg;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.common.appliances.security.antiFormattedBook;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import net.kyori.adventure.text.*;
|
||||||
|
import net.kyori.adventure.text.format.Style;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class AntiFormattedBook extends Appliance {
|
||||||
|
private static final char SECTION = '\u00A7';
|
||||||
|
|
||||||
|
public boolean containsFormatting(BookMeta meta) {
|
||||||
|
if (this.hasFormattingDeep(meta.title())) return true;
|
||||||
|
if (this.hasFormattingDeep(meta.author())) return true;
|
||||||
|
|
||||||
|
for (Component c : meta.pages()) {
|
||||||
|
if (this.hasFormattingDeep(c)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasFormattingDeep(@Nullable Component component) {
|
||||||
|
if(component == null) return false;
|
||||||
|
if (this.hastFormatting(component)) return true;
|
||||||
|
|
||||||
|
if (component instanceof TextComponent tc && tc.content().indexOf(SECTION) >= 0) return true;
|
||||||
|
|
||||||
|
if (component instanceof NBTComponent<?, ?> nbt) {
|
||||||
|
if (nbt.separator() != null && this.hasFormattingDeep(nbt.separator())) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Component child : component.children()) {
|
||||||
|
if (this.hasFormattingDeep(child)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hastFormatting(Component component) {
|
||||||
|
Style style = component.style();
|
||||||
|
|
||||||
|
TextColor color = style.color();
|
||||||
|
if (color != null) return true;
|
||||||
|
if (style.font() != null) return true;
|
||||||
|
if (style.insertion() != null && !Objects.requireNonNull(style.insertion()).isEmpty()) return true;
|
||||||
|
|
||||||
|
for (var decoration : style.decorations().entrySet()) {
|
||||||
|
if (decoration.getValue() == TextDecoration.State.TRUE) return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return style.hoverEvent() != null || style.clickEvent() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<Listener> listeners() {
|
||||||
|
return List.of(
|
||||||
|
new BookEditListener()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.common.appliances.security.antiFormattedBook;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.common.appliances.tooling.acInform.AcInform;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerEditBookEvent;
|
||||||
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
class BookEditListener extends ApplianceListener<AntiFormattedBook> {
|
||||||
|
@EventHandler
|
||||||
|
public void onBookEdit(PlayerEditBookEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
BookMeta meta = event.getNewBookMeta();
|
||||||
|
|
||||||
|
if (this.getAppliance().containsFormatting(meta)) {
|
||||||
|
Main.instance().getAppliance(AcInform.class).notifyAdmins(
|
||||||
|
"internal",
|
||||||
|
player.getName(),
|
||||||
|
"illegalBookFormatting",
|
||||||
|
1f
|
||||||
|
);
|
||||||
|
|
||||||
|
BookMeta sanitized = meta.clone();
|
||||||
|
sanitized.title(null);
|
||||||
|
sanitized.author(null);
|
||||||
|
//noinspection ResultOfMethodCallIgnored
|
||||||
|
sanitized.pages(List.of(Component.empty()));
|
||||||
|
event.setNewBookMeta(sanitized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.common.appliances.security.antiIllegalBundlePicker;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.common.appliances.tooling.acInform.AcInform;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.InventoryView;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.BundleMeta;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class AntiIllegalBundlePicker extends Appliance {
|
||||||
|
private static final int visibleSlotsInBundle = 9;
|
||||||
|
|
||||||
|
public void trackBundle(InventoryClickEvent event) {
|
||||||
|
ItemStack bundle = Objects.requireNonNull(event.getCurrentItem());
|
||||||
|
final int rawSlot = event.getRawSlot();
|
||||||
|
final Player player = (Player) event.getWhoClicked();
|
||||||
|
final InventoryView view = event.getView();
|
||||||
|
final List<ItemStack> before = this.getBundleContents(bundle);
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTask(Main.instance(), () -> {
|
||||||
|
ItemStack afterStack = view.getItem(rawSlot);
|
||||||
|
if(afterStack == null || afterStack.getType() != Material.BUNDLE) return;
|
||||||
|
|
||||||
|
List<ItemStack> after = this.getBundleContents(afterStack);
|
||||||
|
int removedSlotIndex = this.findRemoved(before, after);
|
||||||
|
|
||||||
|
if(removedSlotIndex >= visibleSlotsInBundle) {
|
||||||
|
Main.instance().getAppliance(AcInform.class).notifyAdmins(
|
||||||
|
"internal",
|
||||||
|
player.getName(),
|
||||||
|
"illegalBundlePick",
|
||||||
|
(float) removedSlotIndex
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private int findRemoved(@NotNull List<ItemStack> before, @NotNull List<ItemStack> after) {
|
||||||
|
for (int i = 0; i < Math.max(before.size(), after.size()); i++) {
|
||||||
|
ItemStack a = i < after.size() ? after.get(i) : null;
|
||||||
|
ItemStack b = i < before.size() ? before.get(i) : null;
|
||||||
|
|
||||||
|
if (b == null && a == null) continue;
|
||||||
|
if (b == null) throw new IllegalStateException("Size of bundle was smaller before pickup Action");
|
||||||
|
|
||||||
|
if (a == null) return i;
|
||||||
|
if (!a.isSimilar(b)) return i;
|
||||||
|
if (a.getAmount() != b.getAmount()) return i;
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Failed to find picked Item in bundle");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ItemStack> getBundleContents(@NotNull ItemStack bundle) {
|
||||||
|
if (bundle.getType() != Material.BUNDLE)
|
||||||
|
throw new IllegalStateException("ItemStack is not a bundle");
|
||||||
|
|
||||||
|
BundleMeta meta = (BundleMeta) bundle.getItemMeta();
|
||||||
|
return meta.getItems().stream()
|
||||||
|
.map(ItemStack::clone)
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<Listener> listeners() {
|
||||||
|
return List.of(
|
||||||
|
new OnBundlePickListener()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.common.appliances.security.antiIllegalBundlePicker;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.inventory.InventoryAction;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
class OnBundlePickListener extends ApplianceListener<AntiIllegalBundlePicker> {
|
||||||
|
@EventHandler
|
||||||
|
public void onBundlePick(InventoryClickEvent event) {
|
||||||
|
if(!event.getAction().equals(InventoryAction.PICKUP_FROM_BUNDLE)) return;
|
||||||
|
final ItemStack bundle = event.getCurrentItem();
|
||||||
|
if (bundle == null || bundle.getType() != Material.BUNDLE) return;
|
||||||
|
this.getAppliance().trackBundle(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.common.appliances.tooling.deviceFingerprinting;
|
||||||
|
|
||||||
|
import com.google.common.reflect.TypeToken;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import net.kyori.adventure.resource.ResourcePackInfo;
|
||||||
|
import net.kyori.adventure.resource.ResourcePackRequest;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Appliance.Flags(enabled = false)
|
||||||
|
public class DeviceFingerprinting extends Appliance {
|
||||||
|
public record PackInfo(@NotNull String url, @NotNull UUID uuid, @NotNull String hash) {
|
||||||
|
private static final String failingUrl = "http://127.0.0.1:0";
|
||||||
|
public PackInfo asFailing() {
|
||||||
|
return new PackInfo(failingUrl, this.uuid, this.hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum PackStatus {
|
||||||
|
UNCACHED,
|
||||||
|
CACHED,
|
||||||
|
INVALID;
|
||||||
|
|
||||||
|
public static PackStatus fromBukkitStatus(PlayerResourcePackStatusEvent.Status status) {
|
||||||
|
return switch(status) {
|
||||||
|
case DISCARDED -> CACHED;
|
||||||
|
case FAILED_DOWNLOAD -> UNCACHED;
|
||||||
|
default -> INVALID;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum PlayerStatus {
|
||||||
|
PREPARATION,
|
||||||
|
TESTING,
|
||||||
|
FINISHED,
|
||||||
|
NEW
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PackInfo> packs;
|
||||||
|
private final Map<Player, FingerprintData> fingerprints = new WeakHashMap<>();
|
||||||
|
private final UUID basePackId = UUID.randomUUID();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
this.packs = this.readPacksFromConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startFingerprinting(Player player) {
|
||||||
|
this.fingerprints.put(player, FingerprintData.create(player));
|
||||||
|
Main.logger().info(String.format("Sending base ressource-pack with id '%s' to '%s'%n", this.basePackId, player.getName()));
|
||||||
|
this.sendPack(player, new PackInfo("http://localhost:8080/api/devicefingerprinting/base.zip", this.basePackId, "3296e8bdd30b4f7cffd11c780a1dc70da2948e71"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPackUpdate(Player player, UUID packId, PlayerResourcePackStatusEvent.Status status) {
|
||||||
|
if(!this.fingerprints.containsKey(player)) return;
|
||||||
|
FingerprintData playerFingerprint = this.fingerprints.get(player);
|
||||||
|
if(!playerFingerprint.isInTestingOrPreparation()) return;
|
||||||
|
|
||||||
|
if(packId.equals(this.basePackId)) {
|
||||||
|
Main.logger().info(String.format("Base pack for '%s' updated: '%s'", player.getName(), status));
|
||||||
|
|
||||||
|
if(status != PlayerResourcePackStatusEvent.Status.ACCEPTED) return;
|
||||||
|
Main.logger().info(String.format("Base pack loaded successfully, sending now all packs to '%s'...", player.getName()));
|
||||||
|
playerFingerprint.setTesting();
|
||||||
|
this.packs.forEach(pack -> this.sendPack(player, pack.asFailing()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PackInfo pack = this.packs.stream()
|
||||||
|
.filter(packInfo -> Objects.equals(packInfo.uuid, packId))
|
||||||
|
.findAny()
|
||||||
|
.orElse(null);
|
||||||
|
if(pack == null) return;
|
||||||
|
int packIndex = this.packs.indexOf(pack);
|
||||||
|
|
||||||
|
List<PackStatus> pendingPacks = playerFingerprint.getPendingPacks();
|
||||||
|
PackStatus newPackStatus = PackStatus.fromBukkitStatus(status);
|
||||||
|
if(newPackStatus == PackStatus.INVALID) return;
|
||||||
|
pendingPacks.set(packIndex, newPackStatus);
|
||||||
|
|
||||||
|
playerFingerprint.updateFingerprint();
|
||||||
|
if(Objects.requireNonNull(playerFingerprint.getStatus()) == PlayerStatus.NEW) {
|
||||||
|
Main.logger().info(String.format("Sending fingerprint packs to Player '%s', as it is a unseen Player!", player.getName()));
|
||||||
|
this.sendNewFingerprint(player, Objects.requireNonNull(playerFingerprint.getFingerPrint()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendNewFingerprint(Player player, long fingerprintId) {
|
||||||
|
for (int i = 0; i < this.packs.size(); i++) {
|
||||||
|
if ((fingerprintId & (1L << i)) != 0) {
|
||||||
|
PackInfo pack = this.packs.get(i);
|
||||||
|
this.sendPack(player, pack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendPack(Player player, PackInfo pack) {
|
||||||
|
player.sendResourcePacks(
|
||||||
|
ResourcePackRequest.resourcePackRequest()
|
||||||
|
.required(true)
|
||||||
|
.packs(ResourcePackInfo.resourcePackInfo(pack.uuid, URI.create(pack.url), pack.hash))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DeviceFingerprinting.PackInfo> readPacksFromConfig() {
|
||||||
|
try (InputStreamReader reader = new InputStreamReader(Objects.requireNonNull(Main.class.getResourceAsStream("/deviceFingerprinting/packs.json")))) {
|
||||||
|
Type packListType = new TypeToken<List<DeviceFingerprinting.PackInfo>>(){}.getType();
|
||||||
|
List<DeviceFingerprinting.PackInfo> packs = new Gson().fromJson(reader, packListType);
|
||||||
|
if (packs.isEmpty()) throw new IllegalStateException("No resource packs found in packs.json.");
|
||||||
|
return packs;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException("Failed to parse packs.json.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||||
|
apiBuilder.rawGet(
|
||||||
|
"base.zip",
|
||||||
|
(request, response) -> this.servePack("base.zip", response)
|
||||||
|
);
|
||||||
|
|
||||||
|
for(int i = 0; i < this.packs.size(); i++) {
|
||||||
|
int packIndex = i;
|
||||||
|
apiBuilder.rawGet(
|
||||||
|
String.format("packs/%d", i),
|
||||||
|
(request, response) -> this.servePack(String.valueOf(packIndex), response)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object servePack(String name, Response response) {
|
||||||
|
try {
|
||||||
|
String resourcePath = String.format("/deviceFingerprinting/packs/%s", name);
|
||||||
|
var inputStream = Main.class.getResourceAsStream(resourcePath);
|
||||||
|
|
||||||
|
if (inputStream == null) {
|
||||||
|
throw new IllegalStateException("Pack file not found: " + resourcePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
response.header("Content-Type", "application/zip");
|
||||||
|
response.header("Content-Disposition", String.format("attachment; filename=\"pack-%s.zip\"", name));
|
||||||
|
|
||||||
|
var outputStream = response.raw().getOutputStream();
|
||||||
|
inputStream.transferTo(outputStream);
|
||||||
|
outputStream.close();
|
||||||
|
|
||||||
|
return HttpServer.nothing;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(String.format("Failed to serve pack '%s'", name), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PackInfo> getPacks() {
|
||||||
|
return this.packs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected @NotNull List<Listener> listeners() {
|
||||||
|
return List.of(
|
||||||
|
new PlayerJoinListener()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.common.appliances.tooling.deviceFingerprinting;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
class FingerprintData {
|
||||||
|
public final Player player;
|
||||||
|
private DeviceFingerprinting.PlayerStatus status;
|
||||||
|
private @Nullable Long fingerPrint;
|
||||||
|
private final List<DeviceFingerprinting.PackStatus> pendingPacks;
|
||||||
|
int packCount = Main.instance().getAppliance(DeviceFingerprinting.class).getPacks().size();
|
||||||
|
|
||||||
|
private FingerprintData(Player player) {
|
||||||
|
this.player = player;
|
||||||
|
this.status = DeviceFingerprinting.PlayerStatus.PREPARATION;
|
||||||
|
this.fingerPrint = null;
|
||||||
|
this.pendingPacks = Arrays.asList(new DeviceFingerprinting.PackStatus[this.packCount]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FingerprintData create(Player player) {
|
||||||
|
return new FingerprintData(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTesting() {
|
||||||
|
this.status = DeviceFingerprinting.PlayerStatus.TESTING;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateFingerprint() {
|
||||||
|
long fingerPrint = 0;
|
||||||
|
for (int i = 0; i < this.pendingPacks.size(); i++) {
|
||||||
|
var status = this.pendingPacks.get(i);
|
||||||
|
if(status == null) return;
|
||||||
|
switch (status) {
|
||||||
|
case CACHED:
|
||||||
|
fingerPrint |= 1L << i;
|
||||||
|
break;
|
||||||
|
case UNCACHED:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(fingerPrint == 0) {
|
||||||
|
this.status = DeviceFingerprinting.PlayerStatus.NEW;
|
||||||
|
this.fingerPrint = this.createNewFingerprint();
|
||||||
|
Main.logger().info(String.format("Player %s's was marked as a new Player!", this.player.getName()));
|
||||||
|
} else {
|
||||||
|
this.status = DeviceFingerprinting.PlayerStatus.FINISHED;
|
||||||
|
this.fingerPrint = fingerPrint;
|
||||||
|
}
|
||||||
|
|
||||||
|
Main.logger().info(String.format("Player %s's fingerprint is '%s'", this.player.getName(), fingerPrint));
|
||||||
|
}
|
||||||
|
|
||||||
|
private long createNewFingerprint() {
|
||||||
|
long id = 0;
|
||||||
|
Random random = new Random();
|
||||||
|
for (int i = 0; i < this.packCount / 2; i++) {
|
||||||
|
while (true) {
|
||||||
|
int bitIndex = random.nextInt(this.packCount);
|
||||||
|
if ((id & (1L << bitIndex)) == 0) {
|
||||||
|
id |= 1L << bitIndex;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DeviceFingerprinting.PackStatus> getPendingPacks() {
|
||||||
|
return this.pendingPacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceFingerprinting.PlayerStatus getStatus() {
|
||||||
|
return this.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Long getFingerPrint() {
|
||||||
|
return this.fingerPrint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInTestingOrPreparation() {
|
||||||
|
return this.status == DeviceFingerprinting.PlayerStatus.TESTING || this.status == DeviceFingerprinting.PlayerStatus.PREPARATION;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.common.appliances.tooling.deviceFingerprinting;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
|
||||||
|
|
||||||
|
class PlayerJoinListener extends ApplianceListener<DeviceFingerprinting> {
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
|
this.getAppliance().startFingerprinting(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onResourcePackEvent(PlayerResourcePackStatusEvent event) {
|
||||||
|
this.getAppliance().onPackUpdate(
|
||||||
|
event.getPlayer(),
|
||||||
|
event.getID(),
|
||||||
|
event.getStatus()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
5
common/src/main/resources/deviceFingerprinting/README.md
Normal file
5
common/src/main/resources/deviceFingerprinting/README.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
## Files originally from "TrackPack"
|
||||||
|
https://github.com/ALaggyDev/TrackPack/blob/main/README.md
|
||||||
|
|
||||||
|
|
||||||
|
Discovered by: [Laggy](https://github.com/ALaggyDev/) and [NikOverflow](https://github.com/NikOverflow)
|
||||||
33
common/src/main/resources/deviceFingerprinting/gen_packs.py
Normal file
33
common/src/main/resources/deviceFingerprinting/gen_packs.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import zipfile
|
||||||
|
import hashlib
|
||||||
|
import uuid
|
||||||
|
import json
|
||||||
|
|
||||||
|
SERVER_URL = "http://localhost:8080/api/devicefingerprinting"
|
||||||
|
packs = []
|
||||||
|
|
||||||
|
def file_sha1(path):
|
||||||
|
h = hashlib.sha1()
|
||||||
|
with open(path, "rb") as f:
|
||||||
|
for chunk in iter(lambda: f.read(8192), b""):
|
||||||
|
h.update(chunk)
|
||||||
|
return h.hexdigest()
|
||||||
|
|
||||||
|
for i in range(0, 24):
|
||||||
|
path = f"packs/{i}"
|
||||||
|
|
||||||
|
with zipfile.ZipFile(path, mode="w") as zf:
|
||||||
|
zf.writestr(
|
||||||
|
"pack.mcmeta",
|
||||||
|
'{"pack":{"pack_format":22,"supported_formats":[22,1000],"description":"pack ' + str(i) + '"}}',
|
||||||
|
)
|
||||||
|
|
||||||
|
hash = file_sha1(path)
|
||||||
|
packs.append({
|
||||||
|
"url": f"{SERVER_URL}/packs/{i}",
|
||||||
|
"uuid": str(uuid.uuid4()),
|
||||||
|
"hash": hash
|
||||||
|
})
|
||||||
|
|
||||||
|
with open("packs.json", "w") as f:
|
||||||
|
json.dump(packs, f, indent=4)
|
||||||
122
common/src/main/resources/deviceFingerprinting/packs.json
Normal file
122
common/src/main/resources/deviceFingerprinting/packs.json
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/0",
|
||||||
|
"uuid": "b35f6e2f-1b50-4493-85be-fb18bd90f9bb",
|
||||||
|
"hash": "7a39af839ea6484431f7b707759546bea991d435"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/1",
|
||||||
|
"uuid": "71095b62-d5ef-4ab2-ba3b-3c1b403f5e34",
|
||||||
|
"hash": "a9192ee73df1c5cff2c188fac6e9e638a1e7b6ce"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/2",
|
||||||
|
"uuid": "a4dba0a2-f8f2-4a81-bbb2-a9a818820330",
|
||||||
|
"hash": "6b85b0eb54865dae70bbda89746d83717dc2a214"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/3",
|
||||||
|
"uuid": "79fa2dc4-8c84-45fc-a09f-d89906f0d900",
|
||||||
|
"hash": "c7abf7a316f7e8c98985e8317a8b649e824e9f79"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/4",
|
||||||
|
"uuid": "15702c9b-a22b-426d-b48a-3d65b0368e9a",
|
||||||
|
"hash": "10cd0e2c46f192deb87ac75c149827d44a713017"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/5",
|
||||||
|
"uuid": "3d702d41-8e2f-4920-8dd0-1fd2146da9fb",
|
||||||
|
"hash": "8ad517d259e800b88a38ff00ee6721d5656822f2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/6",
|
||||||
|
"uuid": "c20a2e47-ef43-49da-a80d-adf238df3695",
|
||||||
|
"hash": "798677405a4fd678892e1cf55585c8c91f82e1e2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/7",
|
||||||
|
"uuid": "7ce51b81-1263-4919-9f4e-bb749ffe6e2e",
|
||||||
|
"hash": "af473b8eb7572f35d307bede5f2e20f263c0d804"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/8",
|
||||||
|
"uuid": "0c70d586-fe48-4ffc-86b0-6b9ec3bfe045",
|
||||||
|
"hash": "2fb698ff88f2436637641f3b2e6792201feb5144"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/9",
|
||||||
|
"uuid": "c7af75a8-0b72-495d-a0ff-c1c40e229c13",
|
||||||
|
"hash": "cf660460798eecf451d639873cc1fedc4661db1b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/10",
|
||||||
|
"uuid": "248dbce6-4b2a-44b5-b038-8d718b0ced99",
|
||||||
|
"hash": "a8ebe708d0f3747c76e4e5e68db5dcb561922706"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/11",
|
||||||
|
"uuid": "10979174-cb02-40eb-a754-275551ad608d",
|
||||||
|
"hash": "54961b48db1582a1a0981c8cc9be5ae0f3122cf3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/12",
|
||||||
|
"uuid": "a361cfa7-674c-4493-a4cf-4baff851f276",
|
||||||
|
"hash": "013719dc8da79c96b45a1c5319c20bffe1a56cc9"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/13",
|
||||||
|
"uuid": "24b39bdb-ada9-40ec-9e3a-132c74b81dc6",
|
||||||
|
"hash": "206898c6b6600d2648b2d79c61fc6255b19587d9"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/14",
|
||||||
|
"uuid": "158fc5b4-be2c-4f7a-98cb-af5993adcc90",
|
||||||
|
"hash": "061b266a7c526fb3a3152a4ea70ca5592e0b503c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/15",
|
||||||
|
"uuid": "4f9097a7-be02-48ad-919c-f292307f8490",
|
||||||
|
"hash": "45a667a0fe06246defabca14ef1271fb6db5a1ac"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/16",
|
||||||
|
"uuid": "3ce31e60-7e8a-4fb1-8c6d-da9065bea798",
|
||||||
|
"hash": "75bb12e46203d49e89aa9a826d267552372758bc"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/17",
|
||||||
|
"uuid": "cd978e5c-3de0-4ada-8ec5-3a88a305eec6",
|
||||||
|
"hash": "5b20261f7be03e83e9c52307f1408b0c5e58358c"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/18",
|
||||||
|
"uuid": "75001e58-3999-4779-a1d1-43ab161770ce",
|
||||||
|
"hash": "544420cffb6c17113c06fb49eeba892c208719d3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/19",
|
||||||
|
"uuid": "6a7005a9-c2ca-476d-9a12-07d120ee121a",
|
||||||
|
"hash": "fcc066a4d3193b60b102e3d906ad8dc0b0fcf65b"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/20",
|
||||||
|
"uuid": "521c0d84-d82e-49ef-b096-d9b90f15aa19",
|
||||||
|
"hash": "4545835983ec7f07d02675a69181a80dc396f038"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/21",
|
||||||
|
"uuid": "c1b590c5-43fc-41e3-83c0-47f35b14f845",
|
||||||
|
"hash": "8d4c670eaefc0482734e839b72758226dde13bc3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/22",
|
||||||
|
"uuid": "43958a18-c087-4f2b-a6ea-066231606eb1",
|
||||||
|
"hash": "004282602f7bdbb7cd7724f23aae23876f224092"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "http://localhost:8080/api/devicefingerprinting/packs/23",
|
||||||
|
"uuid": "4b91ac81-9de4-4c2b-a876-47e621496d10",
|
||||||
|
"hash": "dae68eae109e08ea4c4c943905502eb331939f64"
|
||||||
|
}
|
||||||
|
]
|
||||||
1
common/src/main/resources/deviceFingerprinting/packs/.gitignore
vendored
Normal file
1
common/src/main/resources/deviceFingerprinting/packs/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
!base.zip
|
||||||
BIN
common/src/main/resources/deviceFingerprinting/packs/0
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/0
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/1
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/1
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/10
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/10
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/11
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/11
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/12
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/12
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/13
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/13
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/14
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/14
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/15
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/15
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/16
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/16
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/17
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/17
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/18
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/18
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/19
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/19
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/2
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/2
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/20
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/20
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/21
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/21
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/22
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/22
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/23
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/23
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/3
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/3
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/4
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/4
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/5
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/5
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/6
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/6
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/7
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/7
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/8
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/8
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/9
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/9
Normal file
Binary file not shown.
BIN
common/src/main/resources/deviceFingerprinting/packs/base.zip
Normal file
BIN
common/src/main/resources/deviceFingerprinting/packs/base.zip
Normal file
Binary file not shown.
@@ -1,5 +1,5 @@
|
|||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT'
|
compileOnly 'io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT'
|
||||||
compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT'
|
compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT'
|
||||||
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
||||||
implementation 'com.sparkjava:spark-core:2.9.4'
|
implementation 'com.sparkjava:spark-core:2.9.4'
|
||||||
|
|||||||
@@ -51,6 +51,11 @@ public final class Main extends JavaPlugin {
|
|||||||
Main.logger().info("Loading appliances...");
|
Main.logger().info("Loading appliances...");
|
||||||
this.appliances = this.findSubtypesOf(Appliance.class).stream()
|
this.appliances = this.findSubtypesOf(Appliance.class).stream()
|
||||||
.filter(applianceClass -> !disabledAppliances.contains(applianceClass.getSimpleName()))
|
.filter(applianceClass -> !disabledAppliances.contains(applianceClass.getSimpleName()))
|
||||||
|
.filter(appliance -> {
|
||||||
|
Appliance.Flags flags = appliance.getAnnotation(Appliance.Flags.class);
|
||||||
|
if(flags == null) return true;
|
||||||
|
return flags.enabled();
|
||||||
|
})
|
||||||
.map(applianceClass -> {
|
.map(applianceClass -> {
|
||||||
try {
|
try {
|
||||||
return (Appliance) applianceClass.getDeclaredConstructor().newInstance();
|
return (Appliance) applianceClass.getDeclaredConstructor().newInstance();
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ package eu.mhsl.craftattack.spawn.core.api.server;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import eu.mhsl.craftattack.spawn.core.Main;
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.api.server.hooks.HttpHook;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import spark.Request;
|
import spark.Request;
|
||||||
import spark.Spark;
|
import spark.Spark;
|
||||||
|
|
||||||
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@@ -21,6 +23,11 @@ public class HttpServer {
|
|||||||
|
|
||||||
Spark.get("/ping", (request, response) -> System.currentTimeMillis());
|
Spark.get("/ping", (request, response) -> System.currentTimeMillis());
|
||||||
|
|
||||||
|
Spark.post("/hook/:hookId", (request, response) -> {
|
||||||
|
HttpHook.Hook hook = HttpHook.Hook.valueOf(request.params(":hookId").toUpperCase());
|
||||||
|
return hook.getHook().runAction(request.headers(hook.getHeaderAction()), request, response);
|
||||||
|
});
|
||||||
|
|
||||||
Main.instance().getAppliances().forEach(appliance -> appliance.httpApi(new ApiBuilder(appliance)));
|
Main.instance().getAppliances().forEach(appliance -> appliance.httpApi(new ApiBuilder(appliance)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,12 +50,16 @@ public class HttpServer {
|
|||||||
this.applianceName = appliance.getClass().getSimpleName().toLowerCase();
|
this.applianceName = appliance.getClass().getSimpleName().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void rawGet(String path, BiFunction<Request, spark.Response, Object> onCall) {
|
||||||
|
Spark.get(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req, resp)));
|
||||||
|
}
|
||||||
|
|
||||||
public void get(String path, Function<Request, Object> onCall) {
|
public void get(String path, Function<Request, Object> onCall) {
|
||||||
Spark.get(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req)));
|
Spark.get(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rawPost(String path, Function<Request, Object> onCall) {
|
public void rawPost(String path, BiFunction<Request, spark.Response, Object> onCall) {
|
||||||
Spark.post(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req)));
|
Spark.post(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req, resp)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public <TRequest> void post(String path, Class<TRequest> clazz, RequestProvider<TRequest, Request, Object> onCall) {
|
public <TRequest> void post(String path, Class<TRequest> clazz, RequestProvider<TRequest, Request, Object> onCall) {
|
||||||
@@ -59,7 +70,7 @@ public class HttpServer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public String buildRoute(String path) {
|
private String buildRoute(String path) {
|
||||||
return String.format("/api/%s/%s", this.applianceName, path);
|
return String.format("/api/%s/%s", this.applianceName, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.core.api.server.hooks;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.api.server.hooks.impl.WebsiteHook;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public abstract class HttpHook {
|
||||||
|
public enum Hook {
|
||||||
|
WEBSITE("x-webhook-action", new WebsiteHook());
|
||||||
|
|
||||||
|
private final String headerAction;
|
||||||
|
private final HttpHook hook;
|
||||||
|
Hook(String headerAction, HttpHook handler) {
|
||||||
|
this.headerAction = headerAction;
|
||||||
|
this.hook = handler;
|
||||||
|
this.hook.registerHooks();
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpHook getHook() {
|
||||||
|
return this.hook;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHeaderAction() {
|
||||||
|
return this.headerAction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract static class Action {
|
||||||
|
public abstract Object run(Request request, Response response);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Map<String, Action> actions = new HashMap<>();
|
||||||
|
|
||||||
|
protected HttpHook() {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void registerHooks();
|
||||||
|
|
||||||
|
protected void addAction(String name, Action action) {
|
||||||
|
this.actions.put(name, action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object runAction(String action, Request request, Response response) {
|
||||||
|
if(!this.actions.containsKey(action)) {
|
||||||
|
Main.logger().warning(String.format("Webhook-Action '%s' not registered, skipping!", action));
|
||||||
|
return HttpServer.nothing;
|
||||||
|
}
|
||||||
|
return this.actions.get(action).run(request, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.core.api.server.hooks;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class JsonAction<TRequest, TResponse> extends HttpHook.Action {
|
||||||
|
private final Function<TRequest, TResponse> handler;
|
||||||
|
private final Class<TRequest> requestClass;
|
||||||
|
|
||||||
|
private final Gson gson = new Gson();
|
||||||
|
|
||||||
|
public JsonAction(Class<TRequest> requestClass, Function<TRequest, TResponse> handler) {
|
||||||
|
this.requestClass = requestClass;
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object run(Request request, Response response) {
|
||||||
|
TRequest req = this.gson.fromJson(request.body(), this.requestClass);
|
||||||
|
response.type("application/json");
|
||||||
|
return this.gson.toJson(this.handler.apply(req));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.core.api.server.hooks;
|
||||||
|
|
||||||
|
import spark.Request;
|
||||||
|
import spark.Response;
|
||||||
|
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
public class RawAction extends HttpHook.Action {
|
||||||
|
private final BiFunction<Request, Response, Object> handler;
|
||||||
|
public RawAction(BiFunction<Request, Response, Object> handler) {
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object run(Request request, Response response) {
|
||||||
|
return this.handler.apply(request, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.core.api.server.hooks.impl;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.api.server.hooks.HttpHook;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.api.server.hooks.JsonAction;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.event.ReportCreatedEvent;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.event.SpawnEvent;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.event.StrikeCreatedEvent;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class WebsiteHook extends HttpHook {
|
||||||
|
@Override
|
||||||
|
protected void registerHooks() {
|
||||||
|
record CreatedSignup(
|
||||||
|
String firstname,
|
||||||
|
String lastname,
|
||||||
|
String birthday,
|
||||||
|
@Nullable String telephone,
|
||||||
|
String username,
|
||||||
|
String edition,
|
||||||
|
@Nullable UUID uuid
|
||||||
|
) {}
|
||||||
|
this.addAction("signup", new JsonAction<>(CreatedSignup.class, createdSignup -> {
|
||||||
|
Main.logger().info(String.format("New Website-signup from Hook: %s %s (%s)", createdSignup.firstname, createdSignup.lastname, createdSignup.username));
|
||||||
|
return HttpServer.nothing;
|
||||||
|
}));
|
||||||
|
|
||||||
|
record CreatedReport(String reporter, String reported, String reason) {}
|
||||||
|
this.addAction("report", new JsonAction<>(CreatedReport.class, createdReport -> {
|
||||||
|
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 -> {
|
||||||
|
SpawnEvent.call(new StrikeCreatedEvent(new StrikeCreatedEvent.CreatedStrike(createdStrike.uuid)));
|
||||||
|
return HttpServer.nothing;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,8 @@ import org.bukkit.plugin.Plugin;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -23,6 +25,11 @@ import java.util.Optional;
|
|||||||
* Appliances can be enabled or disabled independent of other appliances
|
* Appliances can be enabled or disabled independent of other appliances
|
||||||
*/
|
*/
|
||||||
public abstract class Appliance {
|
public abstract class Appliance {
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface Flags {
|
||||||
|
boolean enabled() default true;
|
||||||
|
}
|
||||||
|
|
||||||
private String localConfigPath;
|
private String localConfigPath;
|
||||||
private List<Listener> listeners;
|
private List<Listener> listeners;
|
||||||
private List<ApplianceCommand<?>> commands;
|
private List<ApplianceCommand<?>> commands;
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.core.event;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ReportCreatedEvent extends Event {
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
@Override
|
||||||
|
public @NotNull HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record CreatedReport(String reporter, String reported, String reason) {}
|
||||||
|
|
||||||
|
private final CreatedReport report;
|
||||||
|
public ReportCreatedEvent(CreatedReport report) {
|
||||||
|
super(true);
|
||||||
|
this.report = report;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CreatedReport getReport() {
|
||||||
|
return this.report;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.core.event;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
public abstract class SpawnEvent {
|
||||||
|
public static void call(Event event) {
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.core.event;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class StrikeCreatedEvent extends Event {
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
@Override
|
||||||
|
public @NotNull HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record CreatedStrike(UUID playerToStrike) {}
|
||||||
|
|
||||||
|
private final CreatedStrike strike;
|
||||||
|
public StrikeCreatedEvent(CreatedStrike strike) {
|
||||||
|
super(true);
|
||||||
|
this.strike = strike;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CreatedStrike getStrike() {
|
||||||
|
return this.strike;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import eu.mhsl.craftattack.spawn.core.util.statistics.ServerMonitor;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.ComponentBuilder;
|
import net.kyori.adventure.text.ComponentBuilder;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -19,7 +20,12 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
public class ComponentUtil {
|
public class ComponentUtil {
|
||||||
public static TextComponent pleaseWait() {
|
public static TextComponent pleaseWait() {
|
||||||
return Component.text("Bitte warte einen Augenblick...", NamedTextColor.GRAY);
|
return Component.text("\uD83D\uDCBE Daten werden geladen... Warte einen Augenblick!", NamedTextColor.GRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TextComponent clickLink(String url) {
|
||||||
|
return Component.text("Klicke, um zu öffnen: \uD83D\uDD17[%s]".formatted(url))
|
||||||
|
.clickEvent(ClickEvent.openUrl(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component clearedSpace() {
|
public static Component clearedSpace() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ dependencies {
|
|||||||
implementation project(':core')
|
implementation project(':core')
|
||||||
implementation project(':common')
|
implementation project(':common')
|
||||||
|
|
||||||
compileOnly 'io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT'
|
compileOnly 'io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT'
|
||||||
compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT'
|
compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT'
|
||||||
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
||||||
implementation 'com.sparkjava:spark-core:2.9.4'
|
implementation 'com.sparkjava:spark-core:2.9.4'
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package eu.mhsl.craftattack.spawn.craftattack.api.repositories;
|
package eu.mhsl.craftattack.spawn.craftattack.api.repositories;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
|
||||||
import eu.mhsl.craftattack.spawn.core.api.client.HttpRepository;
|
import eu.mhsl.craftattack.spawn.core.api.client.HttpRepository;
|
||||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||||
import eu.mhsl.craftattack.spawn.common.api.CraftAttackApi;
|
import eu.mhsl.craftattack.spawn.common.api.CraftAttackApi;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class FeedbackRepository extends HttpRepository {
|
public class FeedbackRepository extends HttpRepository {
|
||||||
@@ -15,14 +12,15 @@ public class FeedbackRepository extends HttpRepository {
|
|||||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||||
}
|
}
|
||||||
|
|
||||||
public record Request(String event, List<UUID> users) {
|
public record Request(String event, String title, List<UUID> users) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReqResp<Map<UUID, String>> createFeedbackUrls(Request data) {
|
public record Response(List<Feedback> feedback) {
|
||||||
final Type responseType = new TypeToken<Map<UUID, String>>() {
|
public record Feedback(UUID uuid, String url) {
|
||||||
}.getType();
|
}
|
||||||
ReqResp<Object> rawData = this.post("feedback", data, Object.class);
|
}
|
||||||
// TODO: use convertToTypeToken from ReqResp
|
|
||||||
return new ReqResp<>(rawData.status(), this.gson.fromJson(this.gson.toJson(rawData.data()), responseType));
|
public ReqResp<Response> createFeedbackUrls(Request data) {
|
||||||
|
return this.post("feedback", data, Response.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import eu.mhsl.craftattack.spawn.core.api.client.HttpRepository;
|
|||||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||||
import eu.mhsl.craftattack.spawn.common.api.CraftAttackApi;
|
import eu.mhsl.craftattack.spawn.common.api.CraftAttackApi;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class WhitelistRepository extends HttpRepository {
|
public class WhitelistRepository extends HttpRepository {
|
||||||
@@ -16,17 +17,15 @@ public class WhitelistRepository extends HttpRepository {
|
|||||||
String username,
|
String username,
|
||||||
String firstname,
|
String firstname,
|
||||||
String lastname,
|
String lastname,
|
||||||
Long banned_until,
|
List<Strike> strikes
|
||||||
Long outlawed_until
|
|
||||||
) {
|
) {
|
||||||
|
public record Strike(long at, int weight) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private record UserQuery(UUID uuid) {}
|
|
||||||
|
|
||||||
public ReqResp<UserData> getUserData(UUID userId) {
|
public ReqResp<UserData> getUserData(UUID userId) {
|
||||||
return this.post(
|
return this.get(
|
||||||
"player",
|
"users/%s".formatted(userId.toString()),
|
||||||
new UserQuery(userId),
|
|
||||||
UserData.class
|
UserData.class
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public class Outlawed extends Appliance implements DisplayName.Prefixed {
|
|||||||
|
|
||||||
void askForConfirmation(Player player) {
|
void askForConfirmation(Player player) {
|
||||||
Component confirmationMessage = switch(this.getLawStatus(player)) {
|
Component confirmationMessage = switch(this.getLawStatus(player)) {
|
||||||
case DISABLED -> Component.text("Wenn du Vogelfrei aktivierst, darfst du von allen Spielern grundlos angegriffen werden.");
|
case DISABLED -> Component.text("Wenn du Vogelfrei aktivierst, darfst du von allen anderen vogelfreien Spielern grundlos angegriffen werden.");
|
||||||
case VOLUNTARILY -> Component.text("Wenn du Vogelfrei deaktivierst, darfst du nicht mehr grundlos von Spielern angegriffen werden.");
|
case VOLUNTARILY -> Component.text("Wenn du Vogelfrei deaktivierst, darfst du nicht mehr grundlos von anderen Spielern angegriffen werden.");
|
||||||
case FORCED -> Component.text("Du darfst zurzeit deinen Vogelfreistatus nicht ändern, da dieser als Strafe auferlegt wurde!");
|
case FORCED -> Component.text("Du darfst zurzeit deinen Vogelfreistatus nicht ändern, da dieser als Strafe auferlegt wurde!");
|
||||||
};
|
};
|
||||||
String command = String.format("/%s confirm", OutlawedCommand.commandName);
|
String command = String.format("/%s confirm", OutlawedCommand.commandName);
|
||||||
@@ -130,7 +130,11 @@ public class Outlawed extends Appliance implements DisplayName.Prefixed {
|
|||||||
.append(Component.text("Es gelten die normalen Regeln!", NamedTextColor.GOLD));
|
.append(Component.text("Es gelten die normalen Regeln!", NamedTextColor.GOLD));
|
||||||
|
|
||||||
case VOLUNTARILY, FORCED -> Component.text("Vogelfreistatus aktiv: ", NamedTextColor.RED)
|
case VOLUNTARILY, FORCED -> Component.text("Vogelfreistatus aktiv: ", NamedTextColor.RED)
|
||||||
.append(Component.text("Du darfst von jedem angegriffen und getötet werden!", NamedTextColor.GOLD));
|
.append(Component.text(
|
||||||
|
"Du darfst von allen anderen vogelfreien Spielern angegriffen und getötet werden!" +
|
||||||
|
"Wenn du getötet wirst, müssen andere Spieler deine Items nicht zurückerstatten!",
|
||||||
|
NamedTextColor.GOLD
|
||||||
|
));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +142,9 @@ public class Outlawed extends Appliance implements DisplayName.Prefixed {
|
|||||||
public Component getNamePrefix(Player player) {
|
public Component getNamePrefix(Player player) {
|
||||||
if(this.isOutlawed(player)) {
|
if(this.isOutlawed(player)) {
|
||||||
return Component.text("[☠]", NamedTextColor.RED)
|
return Component.text("[☠]", NamedTextColor.RED)
|
||||||
.hoverEvent(HoverEvent.showText(Component.text("Vogelfreie Spieler dürfen ohne Grund angegriffen werden!")));
|
.hoverEvent(HoverEvent.showText(Component.text(
|
||||||
|
"Vogelfreie Spieler dürfen von anderen vogelfreien Spielern ohne Grund angegriffen werden!"
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.metaGameplay.feedback;
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.metaGameplay.feedback;
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.core.Main;
|
|
||||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.util.text.ComponentUtil;
|
||||||
import eu.mhsl.craftattack.spawn.craftattack.api.repositories.FeedbackRepository;
|
import eu.mhsl.craftattack.spawn.craftattack.api.repositories.FeedbackRepository;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||||
@@ -9,7 +9,6 @@ import eu.mhsl.craftattack.spawn.core.api.HttpStatus;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.ComponentBuilder;
|
import net.kyori.adventure.text.ComponentBuilder;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.event.ClickEvent;
|
|
||||||
import net.kyori.adventure.text.event.HoverEvent;
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
@@ -18,32 +17,27 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class Feedback extends Appliance {
|
public class Feedback extends Appliance {
|
||||||
public Feedback() {
|
public Feedback() {
|
||||||
super("feedback");
|
super("feedback");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestFeedback(String eventName, List<Player> receivers, @Nullable String question) {
|
public void requestFeedback(String eventName, String title, List<Player> receivers, @Nullable String question) {
|
||||||
ReqResp<Map<UUID, String>> response = this.queryRepository(FeedbackRepository.class).createFeedbackUrls(
|
ReqResp<FeedbackRepository.Response> response = this.queryRepository(FeedbackRepository.class).createFeedbackUrls(
|
||||||
new FeedbackRepository.Request(eventName, receivers.stream().map(Entity::getUniqueId).toList())
|
new FeedbackRepository.Request(eventName, title, receivers.stream().map(Entity::getUniqueId).toList())
|
||||||
);
|
);
|
||||||
|
|
||||||
System.out.println(response.toString());
|
if(response.status() != HttpStatus.OK) throw new RuntimeException();
|
||||||
System.out.println(response.status());
|
|
||||||
|
|
||||||
if(response.status() != HttpStatus.CREATED) throw new RuntimeException();
|
|
||||||
|
|
||||||
Component border = Component.text("-".repeat(40), NamedTextColor.GRAY);
|
Component border = Component.text("-".repeat(40), NamedTextColor.GRAY);
|
||||||
|
|
||||||
receivers.forEach(player -> {
|
receivers.forEach(player -> {
|
||||||
String feedbackUrl = response.data().get(player.getUniqueId());
|
String feedbackUrl = response.data().feedback().stream()
|
||||||
if(feedbackUrl == null) {
|
.filter(feedback -> feedback.uuid().equals(player.getUniqueId()))
|
||||||
Main.logger().warning(String.format("FeedbackUrl not found for player '%s' from backend!", player.getUniqueId()));
|
.findFirst()
|
||||||
return;
|
.orElseThrow()
|
||||||
}
|
.url();
|
||||||
|
|
||||||
ComponentBuilder<TextComponent, TextComponent.Builder> message = Component.text()
|
ComponentBuilder<TextComponent, TextComponent.Builder> message = Component.text()
|
||||||
.append(border)
|
.append(border)
|
||||||
@@ -58,8 +52,7 @@ public class Feedback extends Appliance {
|
|||||||
|
|
||||||
message
|
message
|
||||||
.append(Component.text("Klicke hier und gib uns Feedback, damit wir dein Spielerlebnis verbessern können!", NamedTextColor.DARK_GREEN)
|
.append(Component.text("Klicke hier und gib uns Feedback, damit wir dein Spielerlebnis verbessern können!", NamedTextColor.DARK_GREEN)
|
||||||
.clickEvent(ClickEvent.openUrl(feedbackUrl)))
|
.hoverEvent(HoverEvent.showText(ComponentUtil.clickLink(feedbackUrl))))
|
||||||
.hoverEvent(HoverEvent.showText(Component.text("Klicke, um Feedback zu geben.")))
|
|
||||||
.appendNewline()
|
.appendNewline()
|
||||||
.append(border);
|
.append(border);
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class FeedbackCommand extends ApplianceCommand.PlayerChecked<Feedback> {
|
|||||||
Main.instance(),
|
Main.instance(),
|
||||||
() -> this.getAppliance().requestFeedback(
|
() -> this.getAppliance().requestFeedback(
|
||||||
"self-issued-ingame",
|
"self-issued-ingame",
|
||||||
|
"Dein Feedback an uns",
|
||||||
List.of(this.getPlayer()),
|
List.of(this.getPlayer()),
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class RequestFeedbackCommand extends ApplianceCommand<Feedback> {
|
|||||||
Main.instance(),
|
Main.instance(),
|
||||||
() -> this.getAppliance().requestFeedback(
|
() -> this.getAppliance().requestFeedback(
|
||||||
"admin-issued-ingame",
|
"admin-issued-ingame",
|
||||||
|
"Hilf uns dein Spielerlebnis zu verbessern!",
|
||||||
new ArrayList<>(Bukkit.getOnlinePlayers()), String.join(" ", args)
|
new ArrayList<>(Bukkit.getOnlinePlayers()), String.join(" ", args)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.statistics;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Statistic;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Statistics extends Appliance {
|
||||||
|
record StatisticsResponse(List<PlayerStatistics> playerStatistics) {
|
||||||
|
record PlayerStatistics(String playerName, String playerUuid, List<MaterialStatistic> statistics) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
record MaterialStatistic(String name, String material, int value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
record StatisticsRequest(List<MaterialStatistic> categories) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||||
|
apiBuilder.post(
|
||||||
|
"getStatistics",
|
||||||
|
StatisticsRequest.class,
|
||||||
|
(statistics, request) -> {
|
||||||
|
Main.instance().getLogger().info("API requested statistics");
|
||||||
|
List<StatisticsResponse.PlayerStatistics> statisticsList = Arrays.stream(Bukkit.getOfflinePlayers())
|
||||||
|
.parallel()
|
||||||
|
.map(player -> new StatisticsResponse.PlayerStatistics(
|
||||||
|
player.getName(),
|
||||||
|
player.getUniqueId().toString(),
|
||||||
|
statistics.categories().stream()
|
||||||
|
.map(category -> {
|
||||||
|
String material = (category.material() == null || category.material().isBlank()) ? null : category.material();
|
||||||
|
return new MaterialStatistic(category.name(), material, material == null
|
||||||
|
? player.getStatistic(Statistic.valueOf(category.name()))
|
||||||
|
: player.getStatistic(Statistic.valueOf(category.name()), Material.valueOf(material))
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.toList()
|
||||||
|
))
|
||||||
|
.toList();
|
||||||
|
return new StatisticsResponse(statisticsList);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.strikes;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
|
import eu.mhsl.craftattack.spawn.craftattack.api.repositories.WhitelistRepository;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Strikes extends Appliance {
|
||||||
|
public Strikes() {
|
||||||
|
super("strike");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final BanInfo falseInfo = new BanInfo(false, null, false);
|
||||||
|
public record BanInfo(boolean isBanned, @Nullable Instant bannedUntil, boolean isPermanent) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Map<Integer, Duration> strikePunishmentMap = Map.of(
|
||||||
|
1, Duration.ofHours(1),
|
||||||
|
2, Duration.ofHours(24),
|
||||||
|
3, Duration.ofDays(3),
|
||||||
|
4, Duration.ofDays(7)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
public BanInfo isBanned(List<WhitelistRepository.UserData.Strike> strikes) {
|
||||||
|
if (strikes.isEmpty()) return falseInfo;
|
||||||
|
|
||||||
|
int strikeCount = strikes.stream().mapToInt(WhitelistRepository.UserData.Strike::weight).sum();
|
||||||
|
if (strikeCount < 1) return falseInfo;
|
||||||
|
if (strikeCount > this.strikePunishmentMap.size()) return new BanInfo(true, null, true);
|
||||||
|
|
||||||
|
Instant lastPunishment = strikes.stream()
|
||||||
|
.map(strike -> Instant.ofEpochMilli(strike.at()))
|
||||||
|
.max(Instant::compareTo)
|
||||||
|
.orElse(Instant.EPOCH);
|
||||||
|
|
||||||
|
Duration duration = this.strikePunishmentMap.get(strikeCount);
|
||||||
|
Instant bannedUntil = lastPunishment.plus(duration);
|
||||||
|
|
||||||
|
boolean stillBanned = bannedUntil.isAfter(Instant.now());
|
||||||
|
|
||||||
|
return new BanInfo(stillBanned, bannedUntil, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.whitelist;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.event.StrikeCreatedEvent;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
|
||||||
|
public class StrikeUpdateListener extends ApplianceListener<Whitelist> {
|
||||||
|
@EventHandler
|
||||||
|
public void onStrikeUpdate(StrikeCreatedEvent event) {
|
||||||
|
this.getAppliance().profileUpdated(event.getStrike().playerToStrike());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,21 +8,18 @@ import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
|||||||
import eu.mhsl.craftattack.spawn.core.api.HttpStatus;
|
import eu.mhsl.craftattack.spawn.core.api.HttpStatus;
|
||||||
import eu.mhsl.craftattack.spawn.core.util.server.Floodgate;
|
import eu.mhsl.craftattack.spawn.core.util.server.Floodgate;
|
||||||
import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo;
|
import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo;
|
||||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.outlawed.Outlawed;
|
import eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.strikes.Strikes;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.time.Instant;
|
import javax.inject.Provider;
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Whitelist extends Appliance {
|
public class Whitelist extends Appliance {
|
||||||
@@ -47,7 +44,6 @@ public class Whitelist extends Appliance {
|
|||||||
player.getUniqueId()
|
player.getUniqueId()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
this.queryAppliance(Outlawed.class).updateForcedStatus(player, this.timestampRelevant(user.outlawed_until()));
|
|
||||||
|
|
||||||
String purePlayerName = Floodgate.isBedrock(player)
|
String purePlayerName = Floodgate.isBedrock(player)
|
||||||
? Floodgate.getBedrockPlayer(player).getUsername()
|
? Floodgate.getBedrockPlayer(player).getUsername()
|
||||||
@@ -67,23 +63,31 @@ public class Whitelist extends Appliance {
|
|||||||
Main.instance().getLogger().info(String.format("Running integrityCheck for %s", name));
|
Main.instance().getLogger().info(String.format("Running integrityCheck for %s", name));
|
||||||
boolean overrideCheck = this.localConfig().getBoolean("overrideIntegrityCheck", false);
|
boolean overrideCheck = this.localConfig().getBoolean("overrideIntegrityCheck", false);
|
||||||
WhitelistRepository.UserData user = overrideCheck
|
WhitelistRepository.UserData user = overrideCheck
|
||||||
? new WhitelistRepository.UserData(uuid, name, "", "", 0L, 0L)
|
? new WhitelistRepository.UserData(uuid, name, "", "", List.of())
|
||||||
: this.fetchUserData(uuid);
|
: this.fetchUserData(uuid);
|
||||||
|
|
||||||
this.userData.put(uuid, user);
|
this.userData.put(uuid, user);
|
||||||
Main.logger().info(String.format("got userdata %s", user.toString()));
|
Main.logger().info(String.format("got userdata %s", user.toString()));
|
||||||
|
|
||||||
if(this.timestampRelevant(user.banned_until())) {
|
Strikes.BanInfo banInfo = Main.instance().getAppliance(Strikes.class).isBanned(user.strikes());
|
||||||
Instant bannedDate = new Date(user.banned_until() * 1000L)
|
Main.logger().info(String.format("got baninfo %s", banInfo.toString()));
|
||||||
.toInstant()
|
|
||||||
.plus(1, ChronoUnit.HOURS);
|
|
||||||
|
|
||||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy").withZone(ZoneOffset.UTC);
|
if (banInfo.isBanned()) {
|
||||||
DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("HH:mm").withZone(ZoneOffset.UTC);
|
Provider<ZonedDateTime> zoned = () -> {
|
||||||
|
Objects.requireNonNull(banInfo.bannedUntil(), "Cannot get zoned date time from null");
|
||||||
|
return banInfo.bannedUntil().atZone(ZoneId.of("Europe/Berlin"));
|
||||||
|
};
|
||||||
|
|
||||||
|
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||||
|
DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("HH:mm");
|
||||||
|
|
||||||
|
String unbanText = banInfo.bannedUntil() != null
|
||||||
|
? String.format("Dein Bann läuft am %s um %s ab!", dateFormat.format(zoned.get()), timeFormat.format(zoned.get()))
|
||||||
|
: "Bandauer ist unbekannt.";
|
||||||
|
|
||||||
throw new DisconnectInfo.Throwable(
|
throw new DisconnectInfo.Throwable(
|
||||||
"Du wurdest vom Server gebannt.",
|
"Du wurdest vom Server gebannt.",
|
||||||
String.format("Dein Bann läuft am %s um %s ab!", dateFormat.format(bannedDate), timeFormat.format(bannedDate)),
|
banInfo.isPermanent() ? "Dein Bann läuft nicht ab!" : unbanText,
|
||||||
"Wende dich an einen Admin für weitere Informationen.",
|
"Wende dich an einen Admin für weitere Informationen.",
|
||||||
uuid
|
uuid
|
||||||
);
|
);
|
||||||
@@ -101,11 +105,6 @@ public class Whitelist extends Appliance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean timestampRelevant(Long timestamp) {
|
|
||||||
if(timestamp == null) return false;
|
|
||||||
return timestamp > System.currentTimeMillis() / 1000L;
|
|
||||||
}
|
|
||||||
|
|
||||||
private WhitelistRepository.UserData fetchUserData(UUID uuid) throws DisconnectInfo.Throwable {
|
private WhitelistRepository.UserData fetchUserData(UUID uuid) throws DisconnectInfo.Throwable {
|
||||||
ReqResp<WhitelistRepository.UserData> response = this.queryRepository(WhitelistRepository.class).getUserData(uuid);
|
ReqResp<WhitelistRepository.UserData> response = this.queryRepository(WhitelistRepository.class).getUserData(uuid);
|
||||||
|
|
||||||
@@ -123,13 +122,9 @@ public class Whitelist extends Appliance {
|
|||||||
return response.data();
|
return response.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void profileUpdated(UUID uuid) {
|
||||||
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
Main.instance().getLogger().info(String.format("API Triggered Profile update for %s", uuid));
|
||||||
record User(UUID user) {
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
}
|
|
||||||
apiBuilder.post("update", User.class, (user, request) -> {
|
|
||||||
Main.instance().getLogger().info(String.format("API Triggered Profile update for %s", user.user));
|
|
||||||
Player player = Bukkit.getPlayer(user.user);
|
|
||||||
if(player != null) {
|
if(player != null) {
|
||||||
try {
|
try {
|
||||||
this.fullIntegrityCheck(player);
|
this.fullIntegrityCheck(player);
|
||||||
@@ -137,6 +132,14 @@ public class Whitelist extends Appliance {
|
|||||||
e.getDisconnectScreen().applyKick(player);
|
e.getDisconnectScreen().applyKick(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||||
|
record User(UUID user) {
|
||||||
|
}
|
||||||
|
apiBuilder.post("update", User.class, (user, request) -> {
|
||||||
|
this.profileUpdated(user.user);
|
||||||
return HttpServer.nothing;
|
return HttpServer.nothing;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -145,7 +148,8 @@ public class Whitelist extends Appliance {
|
|||||||
@NotNull
|
@NotNull
|
||||||
protected List<Listener> listeners() {
|
protected List<Listener> listeners() {
|
||||||
return List.of(
|
return List.of(
|
||||||
new PlayerJoinListener()
|
new PlayerJoinListener(),
|
||||||
|
new StrikeUpdateListener()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ dependencies {
|
|||||||
implementation project(':core')
|
implementation project(':core')
|
||||||
implementation project(':common')
|
implementation project(':common')
|
||||||
|
|
||||||
compileOnly 'io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT'
|
compileOnly 'io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT'
|
||||||
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
||||||
implementation 'com.sparkjava:spark-core:2.9.4'
|
implementation 'com.sparkjava:spark-core:2.9.4'
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user