Compare commits
45 Commits
d3512cb2eb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 8953a19400 | |||
| 85065bcc73 | |||
| 2209b42766 | |||
| bf11bb0b70 | |||
| b98d33af40 | |||
| 0d6b21701f | |||
| b3240cdb22 | |||
| 89c1c4335b | |||
| 71f2da8e99 | |||
| a257b604ea | |||
| ac7e04829e | |||
| 9767896cde | |||
| e015bbb356 | |||
| 1ac19014c1 | |||
| 2087b4c379 | |||
| 4d9548aafc | |||
| 4c63800189 | |||
| b8725bc0f2 | |||
| c90d767f0f | |||
| 143f4ee8eb | |||
| ba2befb467 | |||
| 7a2b9b9763 | |||
| 0b9dc5358d | |||
| 448e9472db | |||
| 933c4c0db0 | |||
| f27474016a | |||
| 17e5b2e049 | |||
| 0ab67bb426 | |||
| 29a362b580 | |||
| 239094971c | |||
| 53dbeff829 | |||
| b5da06fd49 | |||
| b55035f1f0 | |||
| 91a28b4500 | |||
| 23af3ff784 | |||
| c220479052 | |||
| 0565f5de9e | |||
| ff81c91661 | |||
| 1182cb2ed6 | |||
| 045f31d4ca | |||
| 263fd85df7 | |||
| d70b025502 | |||
| e14c87c2fb | |||
| 9433495a52 | |||
| 4955e94306 |
@@ -1,7 +1,7 @@
|
||||
dependencies {
|
||||
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'
|
||||
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
||||
implementation 'com.sparkjava:spark-core:2.9.4'
|
||||
|
||||
@@ -11,17 +11,20 @@ public class CraftAttackReportRepository extends ReportRepository {
|
||||
|
||||
public ReqResp<PlayerReports> queryReports(UUID player) {
|
||||
return this.get(
|
||||
"report",
|
||||
(parameters) -> parameters.addParameter("uuid", player.toString()),
|
||||
"users/%s/reports".formatted(player.toString()),
|
||||
PlayerReports.class
|
||||
);
|
||||
}
|
||||
|
||||
public ReqResp<ReportUrl> createReport(ReportCreationInfo data) {
|
||||
return this.post(
|
||||
"report",
|
||||
"reports",
|
||||
data,
|
||||
ReportUrl.class
|
||||
);
|
||||
}
|
||||
|
||||
public ReqResp<AllReports> queryAllReports() {
|
||||
return this.get("reports", AllReports.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,22 +21,32 @@ public abstract class ReportRepository extends HttpRepository {
|
||||
public record ReportUrl(@NotNull String url) {
|
||||
}
|
||||
|
||||
public enum Status {
|
||||
open,
|
||||
closed,
|
||||
}
|
||||
|
||||
public record PlayerReports(
|
||||
List<Report> from_self,
|
||||
Object to_self
|
||||
List<Report> to_self
|
||||
) {
|
||||
public record Report(
|
||||
@Nullable Reporter reported,
|
||||
@NotNull String subject,
|
||||
boolean draft,
|
||||
@NotNull String status,
|
||||
@Nullable UUID reported,
|
||||
@NotNull String reason,
|
||||
@Nullable Long created,
|
||||
@Nullable Status status,
|
||||
@NotNull String url
|
||||
) {
|
||||
public record Reporter(
|
||||
@NotNull String username,
|
||||
@NotNull String uuid
|
||||
) {
|
||||
}
|
||||
}
|
||||
) { }
|
||||
}
|
||||
|
||||
public record AllReports(List<Report> reports) {
|
||||
public record Report(
|
||||
@NotNull UUID reporter,
|
||||
@Nullable UUID reported,
|
||||
@NotNull String reason,
|
||||
@Nullable Long created,
|
||||
@Nullable Status status,
|
||||
@NotNull String url
|
||||
) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,17 +21,18 @@ class ChatMessagesListener extends ApplianceListener<ChatMessages> {
|
||||
public void onPlayerChatEvent(AsyncChatEvent event) {
|
||||
event.renderer(
|
||||
(source, sourceDisplayName, message, viewer) ->
|
||||
Component.text()
|
||||
Component.text("")
|
||||
.append(this.getAppliance().getReportablePlayerName(source))
|
||||
.append(Component.text(" > ").color(TextColor.color(Color.GRAY.asRGB())))
|
||||
.append(message).color(TextColor.color(Color.SILVER.asRGB()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if(event.joinMessage() == null) return;
|
||||
boolean wasHidden = event.joinMessage() == null;
|
||||
event.joinMessage(null);
|
||||
if(wasHidden) return;
|
||||
IteratorUtil.onlinePlayers(player -> {
|
||||
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
||||
player.sendMessage(
|
||||
@@ -44,7 +45,9 @@ class ChatMessagesListener extends ApplianceListener<ChatMessages> {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
if(event.quitMessage() == null) return;
|
||||
boolean wasHidden = event.quitMessage() == null;
|
||||
event.quitMessage(null);
|
||||
if(wasHidden) return;
|
||||
IteratorUtil.onlinePlayers(player -> {
|
||||
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
||||
player.sendMessage(
|
||||
|
||||
@@ -46,6 +46,4 @@ public class InfoBarSetting extends MultiBoolSetting<InfoBarSetting.InfoBarConfi
|
||||
public Class<?> dataType() {
|
||||
return InfoBarConfiguration.class;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,18 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars;
|
||||
|
||||
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.ApplianceCommand;
|
||||
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.TpsBar;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InfoBars extends Appliance {
|
||||
private final NamespacedKey infoBarKey = new NamespacedKey(Main.instance(), "infobars");
|
||||
private final List<Bar> infoBars = List.of(
|
||||
new TpsBar(),
|
||||
new MsptBar(),
|
||||
@@ -27,41 +20,19 @@ public class InfoBars extends Appliance {
|
||||
);
|
||||
|
||||
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) {
|
||||
this.getEnabledBars(player).forEach(bar -> this.hide(player, bar));
|
||||
this.setEnabledBars(player, List.of());
|
||||
}
|
||||
|
||||
public void show(Player player, String bar) {
|
||||
public void setVisible(Player player, String bar, boolean visible) {
|
||||
this.validateBarName(bar);
|
||||
List<String> existingBars = new ArrayList<>(this.getEnabledBars(player));
|
||||
existingBars.add(bar);
|
||||
if(visible) {
|
||||
player.showBossBar(this.getBarByName(bar).getBossBar());
|
||||
this.setEnabledBars(player, existingBars);
|
||||
}
|
||||
|
||||
public void hide(Player player, String bar) {
|
||||
this.validateBarName(bar);
|
||||
List<String> existingBars = new ArrayList<>(this.getEnabledBars(player));
|
||||
existingBars.remove(bar);
|
||||
} else {
|
||||
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) {
|
||||
@@ -79,13 +50,7 @@ public class InfoBars extends Appliance {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Settings.instance().declareSetting(InfoBarSetting.class);
|
||||
Settings.instance().addChangeListener(InfoBarSetting.class, player -> {
|
||||
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);
|
||||
});
|
||||
Settings.instance().addChangeListener(InfoBarSetting.class, this::showAllEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.api.repositories.ReportRepository;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report.listeners.ReportCreatedListener;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report.listeners.ReportJoinListener;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||
import eu.mhsl.craftattack.spawn.common.api.repositories.CraftAttackReportRepository;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
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.ComponentBuilder;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@@ -15,11 +18,14 @@ 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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class Report extends Appliance {
|
||||
public static Component helpText() {
|
||||
@@ -78,7 +84,7 @@ public class Report extends Appliance {
|
||||
.appendNewline()
|
||||
.append(
|
||||
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()))
|
||||
)
|
||||
.appendNewline()
|
||||
@@ -128,44 +134,80 @@ public class Report extends Appliance {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ReportRepository.PlayerReports.Report> reports = userReports
|
||||
.data()
|
||||
.from_self()
|
||||
.stream()
|
||||
.filter(report -> !report.draft())
|
||||
.toList()
|
||||
.reversed();
|
||||
Function<List<ReportRepository.PlayerReports.Report>, List<ReportRepository.PlayerReports.Report>> filterClosed = reports -> reports.stream()
|
||||
.filter(report -> Objects.equals(report.status(), ReportRepository.Status.closed))
|
||||
.toList();
|
||||
|
||||
if(reports.isEmpty()) {
|
||||
issuer.sendMessage(
|
||||
Component.text()
|
||||
List<ReportRepository.PlayerReports.Report> reportsToOthers = filterClosed.apply(userReports.data().from_self()).reversed();
|
||||
List<ReportRepository.PlayerReports.Report> reportsToSelf = filterClosed.apply(userReports.data().to_self()).reversed();
|
||||
|
||||
ComponentBuilder<TextComponent, TextComponent.Builder> component = Component.text()
|
||||
.append(Component.text(
|
||||
!reportsToSelf.isEmpty()
|
||||
? "Du wurdest insgesamt %d mal von anderen Spielern gemeldet.".formatted(reportsToSelf.size())
|
||||
: "Du wurdest von keinem anderen Spieler gemeldet.",
|
||||
NamedTextColor.GOLD)
|
||||
);
|
||||
|
||||
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))
|
||||
);
|
||||
.append(Component.text("Um jemanden zu melden, nutze /report", NamedTextColor.GRAY));
|
||||
}
|
||||
|
||||
issuer.sendMessage(component.build());
|
||||
}
|
||||
|
||||
public void sendReportsInfo(Player player) {
|
||||
ReqResp<ReportRepository.AllReports> allReportsResponse = this.queryRepository(CraftAttackReportRepository.class).queryAllReports();
|
||||
|
||||
if(allReportsResponse.status() != 200) {
|
||||
Main.logger().warning("Failed to request Reports: " + allReportsResponse.status());
|
||||
return;
|
||||
}
|
||||
|
||||
ComponentBuilder<TextComponent, TextComponent.Builder> component = Component.text()
|
||||
.append(Component.newline())
|
||||
.append(Component.text("Von dir erstellte Reports: ", NamedTextColor.GOLD))
|
||||
.appendNewline();
|
||||
List<ReportRepository.AllReports.Report> allOpenReports = allReportsResponse.data().reports().stream()
|
||||
.filter(report -> report.status() == null && report.created() != null)
|
||||
.toList();
|
||||
|
||||
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();
|
||||
});
|
||||
if(allOpenReports.isEmpty()) return;
|
||||
|
||||
issuer.sendMessage(component.build());
|
||||
player.sendMessage(
|
||||
Component.text("Hey, es gibt noch ", NamedTextColor.GOLD)
|
||||
.append(Component.text(allOpenReports.size(), NamedTextColor.RED))
|
||||
.append(Component.text(" unbearbeitete Reports!", NamedTextColor.GOLD))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new ReportCreatedListener(),
|
||||
new ReportJoinListener()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report.listeners;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report.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,19 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report.listeners;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report.Report;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class ReportJoinListener extends ApplianceListener<Report> {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if(!event.getPlayer().hasPermission("admin")) return;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(
|
||||
Main.instance(),
|
||||
() -> this.getAppliance().sendReportsInfo(event.getPlayer())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,8 @@ public class Settings extends Appliance {
|
||||
BorderWarning,
|
||||
LocatorBar,
|
||||
InfoBars,
|
||||
CoordinateDisplay
|
||||
CoordinateDisplay,
|
||||
Bloodmoon
|
||||
}
|
||||
|
||||
public static Settings instance() {
|
||||
@@ -127,12 +128,12 @@ public class Settings extends Appliance {
|
||||
if(categorizedSettings.isEmpty()) return;
|
||||
|
||||
for(int i = 0; i < categorizedSettings.size(); i++) {
|
||||
int slot = row.get() * 9 + i % 9;
|
||||
inventory.setItem(slot, categorizedSettings.get(i).buildItem());
|
||||
|
||||
if(i % 9 == 8) {
|
||||
if(i % 9 == 0 && i != 0) {
|
||||
row.incrementAndGet();
|
||||
}
|
||||
|
||||
int slot = row.get() * 9 + i % 9;
|
||||
inventory.setItem(slot, categorizedSettings.get(i).buildItem());
|
||||
}
|
||||
row.incrementAndGet();
|
||||
});
|
||||
@@ -142,12 +143,12 @@ public class Settings extends Appliance {
|
||||
.toList();
|
||||
|
||||
for(int i = 0; i < uncategorizedSettings.size(); i++) {
|
||||
int slot = row.get() * 9 + i % 9;
|
||||
inventory.setItem(slot, uncategorizedSettings.get(i).buildItem());
|
||||
|
||||
if(i % 9 == 8) {
|
||||
if(i % 9 == 0 && i != 0) {
|
||||
row.incrementAndGet();
|
||||
}
|
||||
|
||||
int slot = row.get() * 9 + i % 9;
|
||||
inventory.setItem(slot, uncategorizedSettings.get(i).buildItem());
|
||||
}
|
||||
|
||||
player.openInventory(inventory);
|
||||
|
||||
@@ -25,7 +25,7 @@ public class SettingsShortcutSetting extends BoolSetting implements CategorizedS
|
||||
|
||||
@Override
|
||||
protected Boolean defaultValue() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,15 +5,10 @@ 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(
|
||||
@@ -27,14 +22,12 @@ public class AntiBoatFreecam extends Appliance {
|
||||
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(
|
||||
Main.instance().getAppliance(AcInform.class).slowedNotifyAdmins(
|
||||
"internal",
|
||||
player.getName(),
|
||||
"illegalBoatLookYaw",
|
||||
violationCount
|
||||
yawDelta,
|
||||
3000
|
||||
);
|
||||
}),
|
||||
1L,
|
||||
|
||||
@@ -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,77 @@
|
||||
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 == '§';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiInventoryMove;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
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;
|
||||
|
||||
private final Map<UUID, Long> invOpen = new ConcurrentHashMap<>();
|
||||
|
||||
public void setInvOpen(Player player, boolean open) {
|
||||
if(open)
|
||||
this.invOpen.put(player.getUniqueId(), System.currentTimeMillis());
|
||||
else
|
||||
this.invOpen.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean hasInventoryOpen(Player player) {
|
||||
if(!this.invOpen.containsKey(player.getUniqueId())) return false;
|
||||
return this.invOpen.get(player.getUniqueId()) < System.currentTimeMillis() - errorTimeMargin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new InventoryTrackerListener(),
|
||||
new InInventoryMoveListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiInventoryMove;
|
||||
|
||||
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 org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInputEvent;
|
||||
|
||||
class InInventoryMoveListener extends ApplianceListener<AntiInventoryMove> {
|
||||
@EventHandler
|
||||
public void onInput(PlayerInputEvent event) {
|
||||
if(!this.getAppliance().hasInventoryOpen(event.getPlayer())) return;
|
||||
Main.instance().getAppliance(AcInform.class).slowedNotifyAdmins(
|
||||
"internal",
|
||||
event.getPlayer().getName(),
|
||||
"inInventoryMove",
|
||||
-1f,
|
||||
3000
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
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(priority = EventPriority.MONITOR)
|
||||
public void onOpen(InventoryOpenEvent event) {
|
||||
if(!(event.getPlayer() instanceof Player player)) return;
|
||||
if(event.isCancelled()) return;
|
||||
this.getAppliance().setInvOpen(player, true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClose(InventoryCloseEvent event) {
|
||||
if(!(event.getPlayer() instanceof Player player)) return;
|
||||
this.getAppliance().setInvOpen(player, false);
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,20 @@ import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class AcInform extends Appliance {
|
||||
private final Map<String, Map<String, Long>> violationSlowdowns = new ConcurrentHashMap<>();
|
||||
|
||||
public void processCommand(@NotNull String[] args) {
|
||||
String anticheatName = null;
|
||||
String playerName = null;
|
||||
String checkName = null;
|
||||
Float violationCount = null;
|
||||
int notifyEvery = 0;
|
||||
|
||||
for(int i = 0; i < args.length; i++) {
|
||||
if(!args[i].startsWith("--")) continue;
|
||||
@@ -36,13 +42,32 @@ public class AcInform extends Appliance {
|
||||
case "--playerName" -> playerName = value;
|
||||
case "--check" -> checkName = value;
|
||||
case "--violationCount" -> violationCount = value.isEmpty() ? null : Float.valueOf(value);
|
||||
case "--notifyEvery" -> notifyEvery = Integer.parseInt(value);
|
||||
}
|
||||
}
|
||||
|
||||
if(notifyEvery == 0) {
|
||||
this.notifyAdmins(anticheatName, playerName, checkName, violationCount);
|
||||
} else {
|
||||
this.slowedNotifyAdmins(anticheatName, playerName, checkName, violationCount, notifyEvery);
|
||||
}
|
||||
}
|
||||
|
||||
public void slowedNotifyAdmins(@Nullable String anticheatName, @Nullable String playerName, @Nullable String checkName, @Nullable Float violationCount, int notifyEvery) {
|
||||
this.violationSlowdowns.putIfAbsent(playerName, new HashMap<>());
|
||||
|
||||
var slowdowns = this.violationSlowdowns.get(playerName);
|
||||
if(slowdowns.containsKey(checkName)) {
|
||||
if(slowdowns.get(checkName) > System.currentTimeMillis() - notifyEvery) return;
|
||||
}
|
||||
|
||||
this.notifyAdmins(anticheatName, playerName, checkName, violationCount);
|
||||
}
|
||||
|
||||
public void notifyAdmins(@Nullable String anticheatName, @Nullable String playerName, @Nullable String checkName, @Nullable Float violationCount) {
|
||||
this.violationSlowdowns.putIfAbsent(playerName, new HashMap<>());
|
||||
this.violationSlowdowns.get(playerName).put(checkName, System.currentTimeMillis());
|
||||
|
||||
ComponentBuilder<TextComponent, TextComponent.Builder> component = Component.text();
|
||||
NamedTextColor textColor = NamedTextColor.GRAY;
|
||||
|
||||
@@ -85,28 +110,42 @@ public class AcInform extends Appliance {
|
||||
Component.newline()
|
||||
.append(Component.text("⊥ ", NamedTextColor.GRAY))
|
||||
.append(Component.text("[", NamedTextColor.GRAY))
|
||||
.append(Component.text("Report", NamedTextColor.GOLD))
|
||||
.append(Component.text("\uD83D\uDCD6", NamedTextColor.GOLD))
|
||||
.append(Component.text("]", NamedTextColor.GRAY))
|
||||
.clickEvent(ClickEvent.suggestCommand(String.format("/report %s anticheat %s flagged %s", playerName, anticheatName, checkName)))
|
||||
);
|
||||
|
||||
component.append(
|
||||
Component.text(" [", NamedTextColor.GRAY)
|
||||
.append(Component.text("Kick", NamedTextColor.GOLD))
|
||||
.append(Component.text("\u23F1", NamedTextColor.GOLD))
|
||||
.append(Component.text("]", NamedTextColor.GRAY))
|
||||
.clickEvent(ClickEvent.suggestCommand(String.format("/kick %s", playerName)))
|
||||
);
|
||||
|
||||
component.append(
|
||||
Component.text(" [", NamedTextColor.GRAY)
|
||||
.append(Component.text("Panic Ban", NamedTextColor.GOLD))
|
||||
.append(Component.text("\uD83E\uDDB6", NamedTextColor.GOLD))
|
||||
.append(Component.text("]", NamedTextColor.GRAY))
|
||||
.clickEvent(ClickEvent.suggestCommand(String.format("/kickunsuspected %s", playerName)))
|
||||
);
|
||||
|
||||
component.append(
|
||||
Component.text(" [", NamedTextColor.GRAY)
|
||||
.append(Component.text("\u2623", NamedTextColor.GOLD))
|
||||
.append(Component.text("]", NamedTextColor.GRAY))
|
||||
.clickEvent(ClickEvent.suggestCommand(String.format("/kickcrash %s", playerName)))
|
||||
);
|
||||
|
||||
component.append(
|
||||
Component.text(" [", NamedTextColor.GRAY)
|
||||
.append(Component.text("\uD83D\uDD12", NamedTextColor.GOLD))
|
||||
.append(Component.text("]", NamedTextColor.GRAY))
|
||||
.clickEvent(ClickEvent.suggestCommand(String.format("/panicban %s", playerName)))
|
||||
);
|
||||
|
||||
component.append(
|
||||
Component.text(" [", NamedTextColor.GRAY)
|
||||
.append(Component.text("Spectate/Teleport", NamedTextColor.GOLD))
|
||||
.append(Component.text("\uD83D\uDC41", NamedTextColor.GOLD))
|
||||
.append(Component.text("]", NamedTextColor.GRAY))
|
||||
.clickEvent(ClickEvent.suggestCommand(String.format("/grim spectate %s", playerName)))
|
||||
);
|
||||
|
||||
@@ -19,6 +19,7 @@ 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";
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.tooling.kick;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.core.util.entity.PlayerUtils;
|
||||
import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -25,9 +30,36 @@ public class Kick extends Appliance {
|
||||
).applyKick(player);
|
||||
}
|
||||
|
||||
public void unsuspectedKick(@NotNull String playerName) {
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
|
||||
if(player == null)
|
||||
throw new ApplianceCommand.Error("Player not found");
|
||||
|
||||
String material = Material.values()[(int)(Math.random() * Material.values().length)].name();
|
||||
player.kick(Component.text("java.lang.IllegalStateException: Failed to create model for minecraft:%s".formatted(material)));
|
||||
}
|
||||
|
||||
public void crashKick(@NotNull String playerName) {
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
|
||||
if(player == null)
|
||||
throw new ApplianceCommand.Error("Player not found");
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
|
||||
PlayerUtils.sendCube(player, 100, Material.ENCHANTING_TABLE.createBlockData());
|
||||
PlayerUtils.sendCube(player, 5, Material.DIRT.createBlockData());
|
||||
});
|
||||
Bukkit.getScheduler().runTaskLater(Main.instance(), () -> player.kick(Component.empty()), Ticks.TICKS_PER_SECOND * 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected List<ApplianceCommand<?>> commands() {
|
||||
return List.of(new KickCommand());
|
||||
return List.of(
|
||||
new KickCommand(),
|
||||
new KickUnsuspectedCommand(),
|
||||
new KickCrashCommand()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.tooling.kick;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class KickCrashCommand extends ApplianceCommand<Kick> {
|
||||
public KickCrashCommand() {
|
||||
super("kickCrash");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||
if(args.length < 1) throw new Error("Es muss ein Spielername angegeben werden!");
|
||||
this.getAppliance().crashKick(args[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
return super.tabCompleteReducer(
|
||||
Bukkit.getOnlinePlayers().stream().map(Player::getName).toList(),
|
||||
args
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.tooling.kick;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class KickUnsuspectedCommand extends ApplianceCommand<Kick> {
|
||||
public KickUnsuspectedCommand() {
|
||||
super("kickUnsuspected");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||
if(args.length < 1) throw new Error("Es muss ein Spielername angegeben werden!");
|
||||
this.getAppliance().unsuspectedKick(args[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
return super.tabCompleteReducer(
|
||||
Bukkit.getOnlinePlayers().stream().map(Player::getName).toList(),
|
||||
args
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
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'
|
||||
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
||||
implementation 'com.sparkjava:spark-core:2.9.4'
|
||||
|
||||
@@ -51,6 +51,11 @@ public final class Main extends JavaPlugin {
|
||||
Main.logger().info("Loading appliances...");
|
||||
this.appliances = this.findSubtypesOf(Appliance.class).stream()
|
||||
.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 -> {
|
||||
try {
|
||||
return (Appliance) applianceClass.getDeclaredConstructor().newInstance();
|
||||
|
||||
@@ -2,6 +2,7 @@ package eu.mhsl.craftattack.spawn.core.api.server;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
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 org.bukkit.configuration.ConfigurationSection;
|
||||
import spark.Request;
|
||||
@@ -22,6 +23,11 @@ public class HttpServer {
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
@@ -64,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,45 @@
|
||||
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(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;
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -23,6 +25,11 @@ import java.util.Optional;
|
||||
* Appliances can be enabled or disabled independent of other appliances
|
||||
*/
|
||||
public abstract class Appliance {
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Flags {
|
||||
boolean enabled() default true;
|
||||
}
|
||||
|
||||
private String localConfigPath;
|
||||
private List<Listener> listeners;
|
||||
private List<ApplianceCommand<?>> commands;
|
||||
|
||||
@@ -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 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(UUID reporter, UUID 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;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
package eu.mhsl.craftattack.spawn.core.util.entity;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerUtils {
|
||||
public static void resetStatistics(Player player) {
|
||||
for(Statistic statistic : Statistic.values()) {
|
||||
@@ -30,4 +36,30 @@ public class PlayerUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendCube(Player player, int cubeSize, BlockData fakeBlock) {
|
||||
Location loc = player.getLocation();
|
||||
World world = player.getWorld();
|
||||
|
||||
int half = cubeSize / 2;
|
||||
int cx = loc.getBlockX();
|
||||
int cy = loc.getBlockY();
|
||||
int cz = loc.getBlockZ();
|
||||
|
||||
int minY = world.getMinHeight();
|
||||
int maxY = world.getMaxHeight() - 1;
|
||||
|
||||
Map<Location, BlockData> changes = new HashMap<>();
|
||||
|
||||
for (int x = cx - half; x <= cx + half; x++) {
|
||||
for (int y = Math.max(cy - half, minY); y <= Math.min(cy + half, maxY); y++) {
|
||||
for (int z = cz - half; z <= cz + half; z++) {
|
||||
changes.put(new Location(world, x, y, z), fakeBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//noinspection UnstableApiUsage
|
||||
player.sendMultiBlockChange(changes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import eu.mhsl.craftattack.spawn.core.util.statistics.ServerMonitor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentBuilder;
|
||||
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.TextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -19,7 +20,12 @@ import java.util.stream.Stream;
|
||||
|
||||
public class ComponentUtil {
|
||||
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() {
|
||||
|
||||
@@ -2,7 +2,7 @@ dependencies {
|
||||
implementation project(':core')
|
||||
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'
|
||||
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
||||
implementation 'com.sparkjava:spark-core:2.9.4'
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
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.ReqResp;
|
||||
import eu.mhsl.craftattack.spawn.common.api.CraftAttackApi;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FeedbackRepository extends HttpRepository {
|
||||
@@ -15,14 +12,15 @@ public class FeedbackRepository extends HttpRepository {
|
||||
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) {
|
||||
final Type responseType = new TypeToken<Map<UUID, String>>() {
|
||||
}.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 record Response(List<Feedback> feedback) {
|
||||
public record Feedback(UUID uuid, String url) {
|
||||
}
|
||||
}
|
||||
|
||||
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.common.api.CraftAttackApi;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class WhitelistRepository extends HttpRepository {
|
||||
@@ -16,17 +17,15 @@ public class WhitelistRepository extends HttpRepository {
|
||||
String username,
|
||||
String firstname,
|
||||
String lastname,
|
||||
Long banned_until,
|
||||
Long outlawed_until
|
||||
List<Strike> strikes
|
||||
) {
|
||||
public record Strike(long at, int weight) {
|
||||
}
|
||||
}
|
||||
|
||||
private record UserQuery(UUID uuid) {}
|
||||
|
||||
public ReqResp<UserData> getUserData(UUID userId) {
|
||||
return this.post(
|
||||
"player",
|
||||
new UserQuery(userId),
|
||||
return this.get(
|
||||
"users/%s".formatted(userId.toString()),
|
||||
UserData.class
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon;
|
||||
|
||||
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.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.commands.BloodmoonCommand;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener.BloodmoonEntityDamageListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener.BloodmoonMonsterDeathListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener.BloodmoonPlayerJoinListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener.BloodmoonTimeListener;
|
||||
import net.kyori.adventure.bossbar.BossBar;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
public class Bloodmoon extends Appliance {
|
||||
public final Map<EntityType, Set<MobEffect>> affectedMobEffectMap = Map.ofEntries(
|
||||
Map.entry(EntityType.ZOMBIE, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
|
||||
)),
|
||||
Map.entry(EntityType.SKELETON, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.SLOWNESS, 3.5, 1)
|
||||
)),
|
||||
Map.entry(EntityType.SPIDER, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.POISON, 4, 1),
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.NAUSEA, 6, 10)
|
||||
)),
|
||||
Map.entry(EntityType.CREEPER, Set.of(
|
||||
new MobEffect.LightningMobEffect()
|
||||
)),
|
||||
Map.entry(EntityType.HUSK, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
|
||||
)),
|
||||
Map.entry(EntityType.STRAY, Set.of()),
|
||||
Map.entry(EntityType.DROWNED, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
|
||||
)),
|
||||
Map.entry(EntityType.WITCH, Set.of()),
|
||||
Map.entry(EntityType.ZOMBIE_VILLAGER, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.WITHER, 7, 1)
|
||||
)),
|
||||
Map.entry(EntityType.PHANTOM, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.LEVITATION, 1.5, 3)
|
||||
)),
|
||||
Map.entry(EntityType.ENDERMAN, Set.of(
|
||||
new MobEffect.PotionMobEffect(PotionEffectType.SLOWNESS, 2.5, 2)
|
||||
))
|
||||
);
|
||||
public final int expMultiplier = 3;
|
||||
public final double mobDamageMultiplier = 2;
|
||||
public final double mobHealthMultiplier = 2;
|
||||
|
||||
private final ThreadLocalRandom random = ThreadLocalRandom.current();
|
||||
private boolean isActive = false;
|
||||
private final BossBar bossBar = BossBar.bossBar(
|
||||
Component.text("Blutmond", NamedTextColor.DARK_RED),
|
||||
1f,
|
||||
BossBar.Color.RED,
|
||||
BossBar.Overlay.NOTCHED_12,
|
||||
Set.of(BossBar.Flag.CREATE_WORLD_FOG, BossBar.Flag.DARKEN_SCREEN)
|
||||
);
|
||||
private final boolean hordesEnabled = true;
|
||||
private final int hordeSpawnRateTicks = 40 * Ticks.TICKS_PER_SECOND;
|
||||
private final int hordeSpawnRateVariationTicks = 40 * Ticks.TICKS_PER_SECOND;
|
||||
private final int hordeMinPopulation = 3;
|
||||
private final int hordeMaxPopulation = 10;
|
||||
private final int hordeSpawnDistance = 10;
|
||||
private final List<EntityType> hordeMobList = List.of(
|
||||
EntityType.ZOMBIE,
|
||||
EntityType.SKELETON,
|
||||
EntityType.SPIDER
|
||||
);
|
||||
private final Map<Player, @Nullable BukkitTask> hordeSpawnTasks = new WeakHashMap<>();
|
||||
private long lastBloodmoonStartTick = 0;
|
||||
public final int ticksPerDay = 24000;
|
||||
public final int bloodmoonLength = ticksPerDay/2;
|
||||
public final int preStartMessageTicks = Ticks.TICKS_PER_SECOND * 50;
|
||||
private final int bloodmoonFreeDaysAtStart = 3;
|
||||
private final int bloodmoonStartTime = ticksPerDay/2;
|
||||
private final int bloodmoonDayInterval = 30;
|
||||
private final int minBonusDrops = 1;
|
||||
private final int maxBonusDrops = 4;
|
||||
private final Map<ItemStack, Integer> bonusDropWeightMap = Map.of(
|
||||
new ItemStack(Material.IRON_INGOT, 5), 10,
|
||||
new ItemStack(Material.GOLD_INGOT, 2), 5,
|
||||
new ItemStack(Material.DIAMOND, 1), 1,
|
||||
new ItemStack(Material.IRON_BLOCK, 1), 5,
|
||||
new ItemStack(Material.GOLD_BLOCK, 1), 2
|
||||
);
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Settings.instance().declareSetting(BloodmoonSetting.class);
|
||||
}
|
||||
|
||||
public boolean bloodmoonIsActive() {
|
||||
return this.isActive;
|
||||
}
|
||||
|
||||
public void startBloodmoon(long startTick) {
|
||||
this.lastBloodmoonStartTick = startTick;
|
||||
this.isActive = true;
|
||||
Bukkit.getOnlinePlayers().forEach(this::addPlayerToBossBar);
|
||||
this.startHordeSpawning(this.getRandomHordeSpawnDelay());
|
||||
this.sendStartMessages();
|
||||
}
|
||||
|
||||
public void stopBloodmoon() {
|
||||
this.isActive = false;
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.hideBossBar(this.bossBar));
|
||||
this.sendStopMessages();
|
||||
}
|
||||
|
||||
public void updateBossBar() {
|
||||
long tick = Bukkit.getWorlds().getFirst().getFullTime();
|
||||
long sinceStart = tick - this.lastBloodmoonStartTick;
|
||||
float progress = 1f - ((float) sinceStart / this.bloodmoonLength);
|
||||
if(progress < 0) progress = 1f;
|
||||
this.bossBar.progress(progress);
|
||||
}
|
||||
|
||||
public boolean isStartTick(long tick) {
|
||||
long day = tick / this.ticksPerDay;
|
||||
if(day % this.bloodmoonDayInterval != 0 || day - this.bloodmoonFreeDaysAtStart <= 0) return false;
|
||||
long time = tick - (day * this.ticksPerDay);
|
||||
return time == this.bloodmoonStartTime;
|
||||
}
|
||||
|
||||
private int getRandomHordeSpawnDelay() {
|
||||
return this.hordeSpawnRateTicks + this.random.nextInt(this.hordeSpawnRateVariationTicks);
|
||||
}
|
||||
|
||||
private void startHordeSpawning(int delay) {
|
||||
Bukkit.getOnlinePlayers().forEach(player -> this.startHordeSpawning(delay, player));
|
||||
}
|
||||
|
||||
private void startHordeSpawning(int delay, Player player) {
|
||||
@Nullable BukkitTask task = this.hordeSpawnTasks.get(player);
|
||||
if(task != null) task.cancel();
|
||||
BukkitTask newTask = Bukkit.getScheduler().runTaskLater(
|
||||
Main.instance(),
|
||||
() -> {
|
||||
if(!this.bloodmoonIsActive()) return;
|
||||
this.spawnRandomHorde(player);
|
||||
this.startHordeSpawning(this.getRandomHordeSpawnDelay(), player);
|
||||
},
|
||||
delay
|
||||
);
|
||||
this.hordeSpawnTasks.put(player, newTask);
|
||||
}
|
||||
|
||||
public void addPlayerToBossBar(Player player) {
|
||||
if(!this.getBloodmoonSetting(player)) return;
|
||||
player.showBossBar(this.bossBar);
|
||||
}
|
||||
|
||||
public boolean isAffectedMob(Entity entity) {
|
||||
return this.affectedMobEffectMap.containsKey(entity.getType());
|
||||
}
|
||||
|
||||
public boolean getBloodmoonSetting(Player player) {
|
||||
return Settings.instance().getSetting(
|
||||
player,
|
||||
Settings.Key.Bloodmoon,
|
||||
Boolean.class
|
||||
);
|
||||
}
|
||||
|
||||
public void spawnRandomHorde(Player player) {
|
||||
if(!this.hordesEnabled) return;
|
||||
if(!player.getGameMode().equals(GameMode.SURVIVAL)) return;
|
||||
|
||||
EntityType hordeEntityType = this.hordeMobList.get(this.random.nextInt(this.hordeMobList.size()));
|
||||
int hordeSize = this.random.nextInt(this.hordeMinPopulation, this.hordeMaxPopulation + 1);
|
||||
this.spawnHorde(player, hordeSize, hordeEntityType);
|
||||
}
|
||||
|
||||
public void sendWarningMessage(Player p) {
|
||||
p.sendMessage(Component.text("Der Blutmond waltet in diesem Augenblick!", NamedTextColor.RED));
|
||||
}
|
||||
|
||||
public void sendAnnouncementMessages() {
|
||||
this.sendMessage(Component.text("Der Blutmond naht; morgen wird er den Himmel beherrschen", NamedTextColor.GOLD));
|
||||
}
|
||||
|
||||
public void sendPreStartMessages() {
|
||||
this.sendMessage(Component.text("Der Himmel ist heute Nacht ungewöhnlich düster", NamedTextColor.DARK_PURPLE));
|
||||
}
|
||||
|
||||
private void spawnHorde(Player player, int size, EntityType type) {
|
||||
for(int i = 0; i < size; i++) {
|
||||
double spawnRadiant = this.random.nextDouble(0, 2*Math.PI);
|
||||
Location mobSpawnLocation = player.getLocation().add(
|
||||
Math.sin(spawnRadiant)*this.hordeSpawnDistance,
|
||||
0,
|
||||
Math.cos(spawnRadiant)*this.hordeSpawnDistance
|
||||
);
|
||||
mobSpawnLocation.setY(player.getWorld().getHighestBlockYAt(mobSpawnLocation) + 1);
|
||||
player.getWorld().spawnEntity(mobSpawnLocation, type);
|
||||
player.getWorld().strikeLightningEffect(mobSpawnLocation);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemStack> getRandomBonusDrops() {
|
||||
int itemCount = this.random.nextInt(this.minBonusDrops, this.maxBonusDrops + 1);
|
||||
List<ItemStack> result = new ArrayList<>();
|
||||
for(int i = 0; i < itemCount; i++) {
|
||||
result.add(this.getRandomBonusDrop());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private @Nullable ItemStack getRandomBonusDrop() {
|
||||
int totalWeight = this.bonusDropWeightMap.values().stream().mapToInt(value -> value).sum();
|
||||
int randomInt = this.random.nextInt(0, totalWeight + 1);
|
||||
int cumulativeWeight = 0;
|
||||
for(Map.Entry<ItemStack, Integer> entry : this.bonusDropWeightMap.entrySet()) {
|
||||
cumulativeWeight += entry.getValue();
|
||||
if(randomInt <= cumulativeWeight) return entry.getKey();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void sendMessage(Component message) {
|
||||
if(Bukkit.getOnlinePlayers().isEmpty()) return;
|
||||
List<? extends Player> onlinePlayers = Bukkit.getOnlinePlayers().stream()
|
||||
.filter(this::getBloodmoonSetting)
|
||||
.toList();
|
||||
onlinePlayers.forEach(player -> player.sendMessage(message));
|
||||
}
|
||||
|
||||
private void sendStartMessages() {
|
||||
this.sendMessage(
|
||||
Component.empty()
|
||||
.append(Component.text("Der Blutmond ist über uns", NamedTextColor.DARK_RED, TextDecoration.BOLD))
|
||||
.appendNewline()
|
||||
.append(Component.text("Erfahrung vervielfacht sich und Mobs lassen reichere Beute fallen", NamedTextColor.RED))
|
||||
.appendNewline()
|
||||
.append(Component.text("Mobs sind erstarkt und belegen dich mit finsteren Debuffs", NamedTextColor.RED))
|
||||
);
|
||||
}
|
||||
|
||||
private void sendStopMessages() {
|
||||
this.sendMessage(Component.text("Der Blutmond weicht...", NamedTextColor.GREEN, TextDecoration.BOLD));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new BloodmoonMonsterDeathListener(),
|
||||
new BloodmoonPlayerJoinListener(),
|
||||
new BloodmoonEntityDamageListener(),
|
||||
new BloodmoonTimeListener()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||
return List.of(
|
||||
new BloodmoonCommand()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.CategorizedSetting;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.SettingCategory;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.datatypes.BoolSetting;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.util.world.InteractSounds;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
public class BloodmoonSetting extends BoolSetting implements CategorizedSetting {
|
||||
public BloodmoonSetting() {
|
||||
super(Settings.Key.Bloodmoon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SettingCategory category() {
|
||||
return SettingCategory.Gameplay;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String title() {
|
||||
return "Blutmond";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String description() {
|
||||
return "Kämpfe während dem Blutmond gegen stärkere Monster mit besseren Drops. Kann nicht während dem Blutmond geändert werden!";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Material icon() {
|
||||
return Material.SKELETON_SKULL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean defaultValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: Settings deaktivierbar machen
|
||||
|
||||
@Override
|
||||
protected void change(Player player, ClickType clickType) {
|
||||
if(Main.instance().getAppliance(Bloodmoon.class).bloodmoonIsActive()) {
|
||||
InteractSounds.of(player).delete();
|
||||
player.sendMessage(Component.text("Während dem Blutmond kann diese Einstellung nicht geändert werden!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
super.change(player, clickType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon;
|
||||
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
public abstract class MobEffect {
|
||||
public abstract void apply(Player p);
|
||||
|
||||
public static class PotionMobEffect extends MobEffect {
|
||||
private final PotionEffect effect;
|
||||
public PotionMobEffect(PotionEffectType type, double seconds, int amplifier) {
|
||||
this.effect = new PotionEffect(type, (int) (seconds * Ticks.TICKS_PER_SECOND), amplifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Player p) {
|
||||
p.addPotionEffect(this.effect);
|
||||
}
|
||||
}
|
||||
|
||||
public static class LightningMobEffect extends MobEffect {
|
||||
@Override
|
||||
public void apply(Player p) {
|
||||
p.getWorld().strikeLightning(p.getLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.commands;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.Bloodmoon;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BloodmoonCommand extends ApplianceCommand<Bloodmoon> {
|
||||
public BloodmoonCommand() {
|
||||
super("bloodmoon");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||
if(args.length == 0) {
|
||||
sender.sendMessage("Bloodmoon is currently %s.".formatted(this.getAppliance().bloodmoonIsActive() ? "active" : "inactive"));
|
||||
return;
|
||||
}
|
||||
|
||||
switch(args[0]) {
|
||||
case "start": {
|
||||
this.getAppliance().startBloodmoon(0L);
|
||||
sender.sendMessage("Started bloodmoon.");
|
||||
break;
|
||||
}
|
||||
case "stop": {
|
||||
this.getAppliance().stopBloodmoon();
|
||||
sender.sendMessage("Stopped bloodmoon.");
|
||||
break;
|
||||
}
|
||||
default: throw new Error("No such option: '%s' !".formatted(args[0]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if(args.length == 1) return List.of("start", "stop");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.Bloodmoon;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Projectile;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public class BloodmoonEntityDamageListener extends ApplianceListener<Bloodmoon> {
|
||||
@EventHandler
|
||||
public void onEntityDamage(EntityDamageByEntityEvent event) {
|
||||
if(!this.getAppliance().bloodmoonIsActive()) return;
|
||||
Entity damagerEntity = event.getDamager();
|
||||
if(damagerEntity instanceof Projectile projectile) {
|
||||
if(!(projectile.getShooter() instanceof Entity shooter)) return;
|
||||
damagerEntity = shooter;
|
||||
}
|
||||
if(!(damagerEntity instanceof LivingEntity damager && event.getEntity() instanceof LivingEntity receiver)) return;
|
||||
if(event.getFinalDamage() == 0) return;
|
||||
|
||||
if(this.getAppliance().isAffectedMob(damager) && receiver instanceof Player player) {
|
||||
if(!this.getAppliance().getBloodmoonSetting(player)) return;
|
||||
event.setDamage(event.getDamage() * this.getAppliance().mobDamageMultiplier);
|
||||
this.getAppliance().affectedMobEffectMap.get(damager.getType()).forEach(mobEffect -> mobEffect.apply(player));
|
||||
return;
|
||||
}
|
||||
if(this.getAppliance().isAffectedMob(receiver) && damager instanceof Player player) {
|
||||
if(!this.getAppliance().getBloodmoonSetting(player)) return;
|
||||
event.setDamage(event.getDamage() / this.getAppliance().mobHealthMultiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.Bloodmoon;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
|
||||
public class BloodmoonMonsterDeathListener extends ApplianceListener<Bloodmoon> {
|
||||
@EventHandler
|
||||
public void onMonsterDeath(EntityDeathEvent event) {
|
||||
if(!this.getAppliance().bloodmoonIsActive()) return;
|
||||
if(!(event.getDamageSource().getCausingEntity() instanceof Player player)) return;
|
||||
if(!this.getAppliance().getBloodmoonSetting(player)) return;
|
||||
LivingEntity entity = event.getEntity();
|
||||
if(!this.getAppliance().isAffectedMob(entity)) return;
|
||||
|
||||
event.setDroppedExp(event.getDroppedExp() * this.getAppliance().expMultiplier);
|
||||
event.getDrops().addAll(this.getAppliance().getRandomBonusDrops());
|
||||
entity.getWorld().strikeLightningEffect(entity.getLocation());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.Bloodmoon;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class BloodmoonPlayerJoinListener extends ApplianceListener<Bloodmoon> {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if(!this.getAppliance().bloodmoonIsActive()) return;
|
||||
this.getAppliance().addPlayerToBossBar(event.getPlayer());
|
||||
this.getAppliance().sendWarningMessage(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.listener;
|
||||
|
||||
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.bloodmoon.Bloodmoon;
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
public class BloodmoonTimeListener extends ApplianceListener<Bloodmoon> {
|
||||
@EventHandler
|
||||
public void onServerTick(ServerTickStartEvent event) {
|
||||
long currentTime = Bukkit.getWorlds().getFirst().getFullTime();
|
||||
if(this.getAppliance().isStartTick(currentTime)) {
|
||||
this.getAppliance().startBloodmoon(currentTime);
|
||||
return;
|
||||
}
|
||||
if(this.getAppliance().isStartTick(currentTime - this.getAppliance().bloodmoonLength)) {
|
||||
this.getAppliance().stopBloodmoon();
|
||||
return;
|
||||
}
|
||||
if(currentTime % Ticks.TICKS_PER_SECOND == 0) this.getAppliance().updateBossBar();
|
||||
if(this.getAppliance().isStartTick(currentTime + this.getAppliance().ticksPerDay)) {
|
||||
this.getAppliance().sendAnnouncementMessages();
|
||||
return;
|
||||
}
|
||||
if(this.getAppliance().isStartTick(currentTime + this.getAppliance().preStartMessageTicks)) {
|
||||
this.getAppliance().sendPreStartMessages();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,8 +51,8 @@ public class Outlawed extends Appliance implements DisplayName.Prefixed {
|
||||
|
||||
void askForConfirmation(Player player) {
|
||||
Component confirmationMessage = switch(this.getLawStatus(player)) {
|
||||
case DISABLED -> Component.text("Wenn du Vogelfrei aktivierst, darfst du von allen Spielern grundlos angegriffen werden.");
|
||||
case VOLUNTARILY -> Component.text("Wenn du Vogelfrei deaktivierst, darfst du nicht mehr grundlos von Spielern 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 anderen Spielern angegriffen werden.");
|
||||
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);
|
||||
@@ -74,11 +74,11 @@ public class Outlawed extends Appliance implements DisplayName.Prefixed {
|
||||
|
||||
void switchLawStatus(Player player) throws OutlawChangeNotPermitted {
|
||||
if(this.getLawStatus(player).equals(Status.FORCED)) {
|
||||
throw new OutlawChangeNotPermitted("Dein Vogelfreistatus wurde als Strafe auferlegt und kann daher nicht verändert werden.");
|
||||
throw new OutlawChangeNotPermitted("Dein PVP-Status wurde als Strafe auferlegt und kann daher nicht verändert werden.");
|
||||
}
|
||||
|
||||
if(this.isTimeout(player)) {
|
||||
throw new OutlawChangeNotPermitted("Du kannst deinen Vogelfreistatus nicht so schnell wechseln. Bitte warte einige Stunden bevor du umschaltest!");
|
||||
throw new OutlawChangeNotPermitted("Du kannst deinen PVP-Status nicht so schnell wechseln. Bitte warte einige Stunden bevor du umschaltest!");
|
||||
}
|
||||
|
||||
this.setLawStatus(player, this.isOutlawed(player) ? Status.DISABLED : Status.VOLUNTARILY);
|
||||
@@ -126,11 +126,15 @@ public class Outlawed extends Appliance implements DisplayName.Prefixed {
|
||||
|
||||
public Component getStatusDescription(Status status) {
|
||||
return switch(status) {
|
||||
case DISABLED -> Component.text("Vogelfreistatus inaktiv: ", NamedTextColor.GREEN)
|
||||
case DISABLED -> Component.text("PVP-Modus inaktiv: ", NamedTextColor.GREEN)
|
||||
.append(Component.text("Es gelten die normalen Regeln!", NamedTextColor.GOLD));
|
||||
|
||||
case VOLUNTARILY, FORCED -> Component.text("Vogelfreistatus aktiv: ", NamedTextColor.RED)
|
||||
.append(Component.text("Du darfst von jedem angegriffen und getötet werden!", NamedTextColor.GOLD));
|
||||
case VOLUNTARILY, FORCED -> Component.text("PVP-Modus aktiv: ", NamedTextColor.RED)
|
||||
.append(Component.text(
|
||||
"Du darfst von allen anderen PVP-Spielern angegriffen und getötet werden!\n" +
|
||||
"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) {
|
||||
if(this.isOutlawed(player)) {
|
||||
return Component.text("[☠]", NamedTextColor.RED)
|
||||
.hoverEvent(HoverEvent.showText(Component.text("Vogelfreie Spieler dürfen ohne Grund angegriffen werden!")));
|
||||
.hoverEvent(HoverEvent.showText(Component.text(
|
||||
"PVP-Modus Spieler dürfen von anderen vogelfreien Spielern ohne Grund angegriffen werden!"
|
||||
)));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class OutlawedCommand extends ApplianceCommand.PlayerChecked<Outlawed> {
|
||||
public static final String commandName = "vogelfrei";
|
||||
public static final String commandName = "pvp";
|
||||
|
||||
public OutlawedCommand() {
|
||||
super(commandName);
|
||||
|
||||
@@ -2,6 +2,7 @@ package eu.mhsl.craftattack.spawn.craftattack.appliances.metaGameplay.event;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||
import eu.mhsl.craftattack.spawn.core.util.server.Floodgate;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.api.repositories.EventRepository;
|
||||
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
@@ -26,6 +27,7 @@ import org.bukkit.entity.Villager;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.geysermc.cumulus.form.SimpleForm;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
@@ -94,6 +96,10 @@ public class Event extends Appliance {
|
||||
}
|
||||
|
||||
public void joinEvent(Player p) {
|
||||
this.joinEvent(p, false);
|
||||
}
|
||||
|
||||
public void joinEvent(Player p, boolean ignoreBedrock) {
|
||||
if(!this.isOpen) {
|
||||
p.sendMessage(Component.text("Zurzeit ist kein Event geöffnet.", NamedTextColor.RED));
|
||||
return;
|
||||
@@ -109,6 +115,23 @@ public class Event extends Appliance {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!ignoreBedrock && Floodgate.isBedrock(p)) {
|
||||
Floodgate.getBedrockPlayer(p).sendForm(
|
||||
SimpleForm.builder()
|
||||
.title("Achtung!")
|
||||
.content("Je nach deiner Minecraft-Bedrock-Version kann dein Minecraft in den Events abstürzen. " +
|
||||
"Ggf. ist also für dich ein Mitspielen auf der Bedrock-Edition nicht möglich.")
|
||||
.button("Ok, lass es uns versuchen")
|
||||
.button("Abbrechen")
|
||||
.validResultHandler(simpleFormResponse -> {
|
||||
if(simpleFormResponse.clickedButtonId() != 0) return;
|
||||
this.joinEvent(p, true);
|
||||
})
|
||||
.build()
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
Main.instance().getLogger().info("Verbinde mit eventserver: " + p.getName());
|
||||
p.sendMessage(Component.text("Authentifiziere...", NamedTextColor.GREEN));
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
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.util.text.ComponentUtil;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.api.repositories.FeedbackRepository;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
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.ComponentBuilder;
|
||||
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.format.NamedTextColor;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -18,32 +17,27 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Feedback extends Appliance {
|
||||
public Feedback() {
|
||||
super("feedback");
|
||||
}
|
||||
|
||||
public void requestFeedback(String eventName, List<Player> receivers, @Nullable String question) {
|
||||
ReqResp<Map<UUID, String>> response = this.queryRepository(FeedbackRepository.class).createFeedbackUrls(
|
||||
new FeedbackRepository.Request(eventName, receivers.stream().map(Entity::getUniqueId).toList())
|
||||
public void requestFeedback(String eventName, String title, List<Player> receivers, @Nullable String question) {
|
||||
ReqResp<FeedbackRepository.Response> response = this.queryRepository(FeedbackRepository.class).createFeedbackUrls(
|
||||
new FeedbackRepository.Request(eventName, title, receivers.stream().map(Entity::getUniqueId).toList())
|
||||
);
|
||||
|
||||
System.out.println(response.toString());
|
||||
System.out.println(response.status());
|
||||
|
||||
if(response.status() != HttpStatus.CREATED) throw new RuntimeException();
|
||||
if(response.status() != HttpStatus.OK) throw new RuntimeException();
|
||||
|
||||
Component border = Component.text("-".repeat(40), NamedTextColor.GRAY);
|
||||
|
||||
receivers.forEach(player -> {
|
||||
String feedbackUrl = response.data().get(player.getUniqueId());
|
||||
if(feedbackUrl == null) {
|
||||
Main.logger().warning(String.format("FeedbackUrl not found for player '%s' from backend!", player.getUniqueId()));
|
||||
return;
|
||||
}
|
||||
String feedbackUrl = response.data().feedback().stream()
|
||||
.filter(feedback -> feedback.uuid().equals(player.getUniqueId()))
|
||||
.findFirst()
|
||||
.orElseThrow()
|
||||
.url();
|
||||
|
||||
ComponentBuilder<TextComponent, TextComponent.Builder> message = Component.text()
|
||||
.append(border)
|
||||
@@ -58,8 +52,7 @@ public class Feedback extends Appliance {
|
||||
|
||||
message
|
||||
.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(Component.text("Klicke, um Feedback zu geben.")))
|
||||
.hoverEvent(HoverEvent.showText(ComponentUtil.clickLink(feedbackUrl))))
|
||||
.appendNewline()
|
||||
.append(border);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ class FeedbackCommand extends ApplianceCommand.PlayerChecked<Feedback> {
|
||||
Main.instance(),
|
||||
() -> this.getAppliance().requestFeedback(
|
||||
"self-issued-ingame",
|
||||
"Dein Feedback an uns",
|
||||
List.of(this.getPlayer()),
|
||||
null
|
||||
)
|
||||
|
||||
@@ -20,6 +20,7 @@ class RequestFeedbackCommand extends ApplianceCommand<Feedback> {
|
||||
Main.instance(),
|
||||
() -> this.getAppliance().requestFeedback(
|
||||
"admin-issued-ingame",
|
||||
"Hilf uns dein Spielerlebnis zu verbessern!",
|
||||
new ArrayList<>(Bukkit.getOnlinePlayers()), String.join(" ", args)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -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.util.server.Floodgate;
|
||||
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.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import javax.inject.Provider;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Whitelist extends Appliance {
|
||||
@@ -47,7 +44,6 @@ public class Whitelist extends Appliance {
|
||||
player.getUniqueId()
|
||||
);
|
||||
}
|
||||
this.queryAppliance(Outlawed.class).updateForcedStatus(player, this.timestampRelevant(user.outlawed_until()));
|
||||
|
||||
String purePlayerName = Floodgate.isBedrock(player)
|
||||
? Floodgate.getBedrockPlayer(player).getUsername()
|
||||
@@ -67,23 +63,31 @@ public class Whitelist extends Appliance {
|
||||
Main.instance().getLogger().info(String.format("Running integrityCheck for %s", name));
|
||||
boolean overrideCheck = this.localConfig().getBoolean("overrideIntegrityCheck", false);
|
||||
WhitelistRepository.UserData user = overrideCheck
|
||||
? new WhitelistRepository.UserData(uuid, name, "", "", 0L, 0L)
|
||||
? new WhitelistRepository.UserData(uuid, name, "", "", List.of())
|
||||
: this.fetchUserData(uuid);
|
||||
|
||||
this.userData.put(uuid, user);
|
||||
Main.logger().info(String.format("got userdata %s", user.toString()));
|
||||
|
||||
if(this.timestampRelevant(user.banned_until())) {
|
||||
Instant bannedDate = new Date(user.banned_until() * 1000L)
|
||||
.toInstant()
|
||||
.plus(1, ChronoUnit.HOURS);
|
||||
Strikes.BanInfo banInfo = Main.instance().getAppliance(Strikes.class).isBanned(user.strikes());
|
||||
Main.logger().info(String.format("got baninfo %s", banInfo.toString()));
|
||||
|
||||
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("dd.MM.yyyy").withZone(ZoneOffset.UTC);
|
||||
DateTimeFormatter timeFormat = DateTimeFormatter.ofPattern("HH:mm").withZone(ZoneOffset.UTC);
|
||||
if (banInfo.isBanned()) {
|
||||
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(
|
||||
"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.",
|
||||
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 {
|
||||
ReqResp<WhitelistRepository.UserData> response = this.queryRepository(WhitelistRepository.class).getUserData(uuid);
|
||||
|
||||
@@ -123,13 +122,9 @@ public class Whitelist extends Appliance {
|
||||
return response.data();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||
record User(UUID user) {
|
||||
}
|
||||
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);
|
||||
public void profileUpdated(UUID uuid) {
|
||||
Main.instance().getLogger().info(String.format("API Triggered Profile update for %s", uuid));
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if(player != null) {
|
||||
try {
|
||||
this.fullIntegrityCheck(player);
|
||||
@@ -137,6 +132,14 @@ public class Whitelist extends Appliance {
|
||||
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;
|
||||
});
|
||||
}
|
||||
@@ -145,7 +148,8 @@ public class Whitelist extends Appliance {
|
||||
@NotNull
|
||||
protected List<Listener> listeners() {
|
||||
return List.of(
|
||||
new PlayerJoinListener()
|
||||
new PlayerJoinListener(),
|
||||
new StrikeUpdateListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ dependencies {
|
||||
implementation project(':core')
|
||||
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 'com.sparkjava:spark-core:2.9.4'
|
||||
}
|
||||
Reference in New Issue
Block a user