24 Commits

Author SHA1 Message Date
aad1fcafa6 added FingerprintData class and improved device fingerprinting logic 2025-10-05 15:46:45 +02:00
9fca7430a8 implemented working fingerprinting prototype 2025-10-05 13:24:47 +02:00
7c254707c1 removed permanent coordinate broadcasting 2025-10-03 17:47:23 +02:00
9ee5f6e419 updated InfoBars to use Bukkit scheduler for data container updates; enhanced CoordinateDisplay with Unicode icons and adjusted text styling 2025-10-03 17:38:29 +02:00
e49c3b1987 added category support to CoordinateDisplaySetting to align with gameplay setting structure 2025-10-03 17:06:56 +02:00
5ca4c70a41 added CoordinateDisplay with settings preferences, directional updates, and time display 2025-10-03 17:06:20 +02:00
040cae6cd1 updated InfoBars: localized names, dynamic coloring, and progress clamping adjustments 2025-10-03 15:49:17 +02:00
324defc4a8 removed InfoBarCommand and integrated InfoBars with Settings preference handling 2025-10-03 15:30:36 +02:00
dc0003b91e Merge branch 'master-antiGrief' 2025-10-01 19:12:01 +02:00
d4a3c798f8 added LocatorBar preferences 2025-10-01 19:11:16 +02:00
c88c2ab6aa updated dependencies 2025-09-28 13:22:42 +02:00
32a20cd4c5 added antiGrief command 2025-09-28 12:59:18 +02:00
d7cc141b94 added antiGrief inhabited chunk time calculation 2025-09-27 07:42:13 +02:00
16d7347fd0 antigrief false positives tweaks 2025-09-27 07:30:23 +02:00
fdf3b5c73f smaller lavaCast detector to prevent natural flow detection 2025-09-21 13:31:21 +02:00
74f17e1b6d WIP: AntiGrief 2025-09-21 01:54:20 +02:00
0d18b81399 changed coloring of VaroRank 2025-09-21 01:06:29 +02:00
1fa5fdfeb7 tweaked settings defaults 2025-09-20 20:35:02 +02:00
3bec5f4cbd added confirmation on outlawed change 2025-09-20 20:30:47 +02:00
d38871eac9 added MendingReducer tweak 2025-09-20 14:43:19 +02:00
238df2feff added armadilloExpFarm tweaks 2025-09-20 13:01:41 +02:00
e752d7f73b moved AntiAutoTotem to common project 2025-09-20 12:51:48 +02:00
b0df982be3 made antiSignEdit message clearer 2025-09-20 12:16:26 +02:00
dc1b5957f6 WIP: different method for grief detection 2025-09-20 11:35:19 +02:00
80 changed files with 1942 additions and 95 deletions

View File

@@ -1,7 +1,7 @@
dependencies { dependencies {
implementation project(':core') implementation project(':core')
compileOnly 'io.papermc.paper:paper-api:1.21.7-R0.1-SNAPSHOT' compileOnly 'io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT'
compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT' compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT'
implementation 'org.apache.httpcomponents:httpclient:4.5.14' implementation 'org.apache.httpcomponents:httpclient:4.5.14'
implementation 'com.sparkjava:spark-core:2.9.4' implementation 'com.sparkjava:spark-core:2.9.4'

View File

@@ -0,0 +1,21 @@
package eu.mhsl.craftattack.spawn.common.appliances.gameplay.cordinateDisplay;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class CoordinateChangedListener extends ApplianceListener<CoordinateDisplay> {
@EventHandler
public void onJoin(PlayerJoinEvent event) {
this.getAppliance().updateEnabled(event.getPlayer());
}
@EventHandler
public void onMove(PlayerMoveEvent event) {
if(!this.getAppliance().isEnabled(event.getPlayer())) return;
boolean hasChangedOrientation = this.getAppliance().hasChangedDirection(event.getFrom(), event.getTo());
if(!event.hasChangedBlock() && !hasChangedOrientation) return;
this.getAppliance().sendCoordinates(event.getPlayer());
}
}

View File

@@ -0,0 +1,93 @@
package eu.mhsl.craftattack.spawn.common.appliances.gameplay.cordinateDisplay;
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
import eu.mhsl.craftattack.spawn.core.util.text.DataSizeConverter;
import eu.mhsl.craftattack.spawn.core.util.world.WorldUtils;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import java.util.*;
public class CoordinateDisplay extends Appliance {
Map<Player, CoordinateDisplaySetting.CoordinateDisplayConfiguration> enabledPlayers = new WeakHashMap<>();
@Override
public void onEnable() {
Settings.instance().declareSetting(CoordinateDisplaySetting.class);
Settings.instance().addChangeListener(CoordinateDisplaySetting.class, this::updateEnabled);
}
public void updateEnabled(Player player) {
CoordinateDisplaySetting.CoordinateDisplayConfiguration configuration = Settings.instance().getSetting(
player,
Settings.Key.CoordinateDisplay,
CoordinateDisplaySetting.CoordinateDisplayConfiguration.class
);
this.enabledPlayers.put(player, configuration);
}
public boolean isEnabled(Player player) {
return Optional.ofNullable(this.enabledPlayers.get(player))
.map(CoordinateDisplaySetting.CoordinateDisplayConfiguration::anyEnabled)
.orElse(false);
}
public void sendCoordinates(Player player) {
CoordinateDisplaySetting.CoordinateDisplayConfiguration config = this.enabledPlayers.get(player);
List<Component> components = new ArrayList<>();
if (config.coordinates()) {
components.add(Component.text("\uD83C\uDF0E ", NamedTextColor.GOLD));
components.add(Component.text(String.format(
"%d %d %d",
player.getLocation().getBlockX(),
player.getLocation().getBlockY(),
player.getLocation().getBlockZ()
)));
}
if (config.direction()) {
if (!components.isEmpty()) {
components.add(Component.text(" | ", NamedTextColor.GRAY));
}
components.add(Component.text("\uD83E\uDDED ", NamedTextColor.GOLD));
components.add(Component.text(DataSizeConverter.getCardinalDirection(player.getLocation())));
}
if (config.time()) {
if (!components.isEmpty()) {
components.add(Component.text(" | ", NamedTextColor.GRAY));
}
components.add(Component.text("", NamedTextColor.GOLD));
components.add(Component.text(WorldUtils.getGameTime(player.getWorld())));
}
if (!components.isEmpty()) {
Component actionBar = Component.empty();
for (Component component : components) {
actionBar = actionBar.append(component);
}
player.sendActionBar(actionBar);
}
}
public boolean hasChangedDirection(Location previous, Location next) {
return !Objects.equals(
DataSizeConverter.getCardinalDirection(previous),
DataSizeConverter.getCardinalDirection(next)
);
}
@Override
protected @NotNull List<Listener> listeners() {
return List.of(
new CoordinateChangedListener()
);
}
}

View File

@@ -0,0 +1,53 @@
package eu.mhsl.craftattack.spawn.common.appliances.gameplay.cordinateDisplay;
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.MultiBoolSetting;
import org.bukkit.Material;
public class CoordinateDisplaySetting extends MultiBoolSetting<CoordinateDisplaySetting.CoordinateDisplayConfiguration> implements CategorizedSetting {
public CoordinateDisplaySetting() {
super(Settings.Key.CoordinateDisplay);
}
@Override
public SettingCategory category() {
return SettingCategory.Gameplay;
}
public record CoordinateDisplayConfiguration(
@DisplayName("Koordinaten") boolean coordinates,
@DisplayName("Richtung") boolean direction,
@DisplayName("Zeit") boolean time
) {
public boolean anyEnabled() {
return this.coordinates || this.direction || this.time;
}
}
@Override
protected String title() {
return "Koordinatenanzeige";
}
@Override
protected String description() {
return "Zeige deine aktuelle Position über der Hotbar an";
}
@Override
protected Material icon() {
return Material.RECOVERY_COMPASS;
}
@Override
protected CoordinateDisplayConfiguration defaultValue() {
return new CoordinateDisplayConfiguration(false, false, false);
}
@Override
public Class<?> dataType() {
return CoordinateDisplayConfiguration.class;
}
}

View File

@@ -13,6 +13,7 @@ import java.time.temporal.ChronoUnit;
public abstract class Bar { public abstract class Bar {
private BossBar bossBar; private BossBar bossBar;
private final BukkitTask updateTask; private final BukkitTask updateTask;
public static String name;
public Bar() { public Bar() {
long refreshRateInTicks = this.refresh().get(ChronoUnit.SECONDS) * Ticks.TICKS_PER_SECOND; long refreshRateInTicks = this.refresh().get(ChronoUnit.SECONDS) * Ticks.TICKS_PER_SECOND;
@@ -32,7 +33,7 @@ public abstract class Bar {
private BossBar createBar() { private BossBar createBar() {
return BossBar.bossBar( return BossBar.bossBar(
this.title(), this.title(),
this.correctedProgress(), this.clampedProgress(),
this.color(), this.color(),
this.overlay() this.overlay()
); );
@@ -43,7 +44,7 @@ public abstract class Bar {
this.beforeRefresh(); this.beforeRefresh();
this.bossBar.name(this.title()); this.bossBar.name(this.title());
this.bossBar.progress(this.correctedProgress()); this.bossBar.progress(this.clampedProgress());
this.bossBar.color(this.color()); this.bossBar.color(this.color());
this.bossBar.overlay(this.overlay()); this.bossBar.overlay(this.overlay());
} }
@@ -52,7 +53,7 @@ public abstract class Bar {
this.updateTask.cancel(); this.updateTask.cancel();
} }
private float correctedProgress() { private float clampedProgress() {
return Math.clamp(this.progress(), 0, 1); return Math.clamp(this.progress(), 0, 1);
} }

View File

@@ -1,32 +0,0 @@
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
class InfoBarCommand extends ApplianceCommand.PlayerChecked<InfoBars> {
public InfoBarCommand() {
super("infobar");
}
@Override
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
if(args.length == 0) throw new Error("<show|hide|hideall> [bar name]");
switch(args[0]) {
case "hideAll" -> this.getAppliance().hideAll(this.getPlayer());
case "show" -> this.getAppliance().show(this.getPlayer(), args[1]);
case "hide" -> this.getAppliance().hide(this.getPlayer(), args[1]);
default -> throw new Error("Erlaubte Optionen sind 'show', 'hide', 'hideAll'!");
}
}
@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("show", "hide", "hideAll");
return this.getAppliance().getInfoBars().stream().map(Bar::name).toList();
}
}

View File

@@ -0,0 +1,51 @@
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars;
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.MultiBoolSetting;
import org.bukkit.Material;
public class InfoBarSetting extends MultiBoolSetting<InfoBarSetting.InfoBarConfiguration> implements CategorizedSetting {
public InfoBarSetting() {
super(Settings.Key.InfoBars);
}
@Override
public SettingCategory category() {
return SettingCategory.Misc;
}
public record InfoBarConfiguration(
@DisplayName("Millisekunden pro Tick") boolean mspt,
@DisplayName("Spieler online") boolean playerCounter,
@DisplayName("Ticks pro Sekunde") boolean tps
) {}
@Override
protected String title() {
return "Informationsleisten";
}
@Override
protected String description() {
return "Wähle anzuzeigende Informationsleisten aus";
}
@Override
protected Material icon() {
return Material.COMMAND_BLOCK;
}
@Override
protected InfoBarConfiguration defaultValue() {
return new InfoBarConfiguration(false, false, false);
}
@Override
public Class<?> dataType() {
return InfoBarConfiguration.class;
}
}

View File

@@ -1,11 +1,13 @@
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars; package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars;
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
import eu.mhsl.craftattack.spawn.core.Main; import eu.mhsl.craftattack.spawn.core.Main;
import eu.mhsl.craftattack.spawn.core.appliance.Appliance; import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand; import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.MsptBar; import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.MsptBar;
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.PlayerCounterBar; import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.PlayerCounterBar;
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.TpsBar; import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.TpsBar;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -24,39 +26,42 @@ public class InfoBars extends Appliance {
new PlayerCounterBar() new PlayerCounterBar()
); );
public void showAll(Player player) { public void showAllEnabled(Player player) {
this.getStoredBars(player).forEach(bar -> this.show(player, bar)); this.getEnabledBars(player).forEach(bar -> this.show(player, bar));
} }
public void hideAll(Player player) { public void hideAllEnabled(Player player) {
this.getStoredBars(player).forEach(bar -> this.hide(player, bar)); this.getEnabledBars(player).forEach(bar -> this.hide(player, bar));
this.setStoredBars(player, List.of()); this.setEnabledBars(player, List.of());
} }
public void show(Player player, String bar) { public void show(Player player, String bar) {
this.validateBarName(bar); this.validateBarName(bar);
List<String> existingBars = new ArrayList<>(this.getStoredBars(player)); List<String> existingBars = new ArrayList<>(this.getEnabledBars(player));
existingBars.add(bar); existingBars.add(bar);
player.showBossBar(this.getBarByName(bar).getBossBar()); player.showBossBar(this.getBarByName(bar).getBossBar());
this.setStoredBars(player, existingBars); this.setEnabledBars(player, existingBars);
} }
public void hide(Player player, String bar) { public void hide(Player player, String bar) {
this.validateBarName(bar); this.validateBarName(bar);
List<String> existingBars = new ArrayList<>(this.getStoredBars(player)); List<String> existingBars = new ArrayList<>(this.getEnabledBars(player));
existingBars.remove(bar); existingBars.remove(bar);
player.hideBossBar(this.getBarByName(bar).getBossBar()); player.hideBossBar(this.getBarByName(bar).getBossBar());
this.setStoredBars(player, existingBars); this.setEnabledBars(player, existingBars);
} }
private List<String> getStoredBars(Player player) { private List<String> getEnabledBars(Player player) {
PersistentDataContainer container = player.getPersistentDataContainer(); PersistentDataContainer container = player.getPersistentDataContainer();
if(!container.has(this.infoBarKey)) return List.of(); if(!container.has(this.infoBarKey)) return List.of();
return container.get(this.infoBarKey, PersistentDataType.LIST.strings()); return container.get(this.infoBarKey, PersistentDataType.LIST.strings());
} }
private void setStoredBars(Player player, List<String> bars) { private void setEnabledBars(Player player, List<String> bars) {
player.getPersistentDataContainer().set(this.infoBarKey, PersistentDataType.LIST.strings(), bars); Bukkit.getScheduler().runTask(
Main.instance(),
() -> player.getPersistentDataContainer().set(this.infoBarKey, PersistentDataType.LIST.strings(), bars)
);
} }
private Bar getBarByName(String name) { private Bar getBarByName(String name) {
@@ -71,8 +76,16 @@ public class InfoBars extends Appliance {
throw new ApplianceCommand.Error(String.format("Ungültiger infobar name '%s'", name)); throw new ApplianceCommand.Error(String.format("Ungültiger infobar name '%s'", name));
} }
public List<Bar> getInfoBars() { @Override
return this.infoBars; 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);
});
} }
@Override @Override
@@ -84,9 +97,4 @@ public class InfoBars extends Appliance {
protected @NotNull List<Listener> listeners() { protected @NotNull List<Listener> listeners() {
return List.of(new ShowPreviousBarsListener()); return List.of(new ShowPreviousBarsListener());
} }
@Override
protected @NotNull List<ApplianceCommand<?>> commands() {
return List.of(new InfoBarCommand());
}
} }

View File

@@ -7,6 +7,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
class ShowPreviousBarsListener extends ApplianceListener<InfoBars> { class ShowPreviousBarsListener extends ApplianceListener<InfoBars> {
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent event) { public void onJoin(PlayerJoinEvent event) {
// this.getAppliance().showAll(event.getPlayer()); this.getAppliance().showAllEnabled(event.getPlayer());
} }
} }

View File

@@ -10,6 +10,8 @@ import net.kyori.adventure.text.format.NamedTextColor;
import java.time.Duration; import java.time.Duration;
public class MsptBar extends Bar { public class MsptBar extends Bar {
public static String name = "msptd";
@Override @Override
protected Duration refresh() { protected Duration refresh() {
return Duration.ofSeconds(3); return Duration.ofSeconds(3);
@@ -17,7 +19,7 @@ public class MsptBar extends Bar {
@Override @Override
protected String name() { protected String name() {
return "mspt"; return name;
} }
@Override @Override
@@ -25,10 +27,10 @@ public class MsptBar extends Bar {
return Component.text() return Component.text()
.append(Component.text("M")) .append(Component.text("M"))
.append(Component.text("illi", NamedTextColor.GRAY)) .append(Component.text("illi", NamedTextColor.GRAY))
.append(Component.text("S")) .append(Component.text("s"))
.append(Component.text("econds ", NamedTextColor.GRAY)) .append(Component.text("ekunden ", NamedTextColor.GRAY))
.append(Component.text("P")) .append(Component.text("p"))
.append(Component.text("er ", NamedTextColor.GRAY)) .append(Component.text("ro ", NamedTextColor.GRAY))
.append(Component.text("T")) .append(Component.text("T"))
.append(Component.text("ick", NamedTextColor.GRAY)) .append(Component.text("ick", NamedTextColor.GRAY))
.append(Component.text(": ")) .append(Component.text(": "))
@@ -43,7 +45,7 @@ public class MsptBar extends Bar {
@Override @Override
protected BossBar.Color color() { protected BossBar.Color color() {
return BossBar.Color.BLUE; return this.currentMSPT() <= 50 ? BossBar.Color.GREEN : BossBar.Color.RED;
} }
@Override @Override

View File

@@ -12,6 +12,8 @@ import org.bukkit.Bukkit;
import java.time.Duration; import java.time.Duration;
public class PlayerCounterBar extends Bar { public class PlayerCounterBar extends Bar {
public static String name = "playerCounter";
@Override @Override
protected Duration refresh() { protected Duration refresh() {
return Duration.ofSeconds(3); return Duration.ofSeconds(3);
@@ -19,7 +21,7 @@ public class PlayerCounterBar extends Bar {
@Override @Override
protected String name() { protected String name() {
return "playerCounter"; return name;
} }
@Override @Override
@@ -38,7 +40,10 @@ public class PlayerCounterBar extends Bar {
@Override @Override
protected BossBar.Color color() { protected BossBar.Color color() {
return BossBar.Color.BLUE; int freeSlots = this.getMaxPlayerCount() - this.getCurrentPlayerCount();
return freeSlots <= 0
? BossBar.Color.RED
: freeSlots < 5 ? BossBar.Color.YELLOW : BossBar.Color.GREEN;
} }
@Override @Override

View File

@@ -10,6 +10,8 @@ import org.bukkit.Bukkit;
import java.time.Duration; import java.time.Duration;
public class TpsBar extends Bar { public class TpsBar extends Bar {
public static String name = "tps";
@Override @Override
protected Duration refresh() { protected Duration refresh() {
return Duration.ofSeconds(3); return Duration.ofSeconds(3);
@@ -17,7 +19,7 @@ public class TpsBar extends Bar {
@Override @Override
protected String name() { protected String name() {
return "tps"; return name;
} }
@Override @Override
@@ -25,10 +27,10 @@ public class TpsBar extends Bar {
return Component.text() return Component.text()
.append(Component.text("T")) .append(Component.text("T"))
.append(Component.text("icks ", NamedTextColor.GRAY)) .append(Component.text("icks ", NamedTextColor.GRAY))
.append(Component.text("P")) .append(Component.text("p"))
.append(Component.text("er ", NamedTextColor.GRAY)) .append(Component.text("ro ", NamedTextColor.GRAY))
.append(Component.text("S")) .append(Component.text("S"))
.append(Component.text("econds", NamedTextColor.GRAY)) .append(Component.text("ekunde", NamedTextColor.GRAY))
.append(Component.text(": ")) .append(Component.text(": "))
.append(Component.text(String.format("%.2f", this.currentTps()), ColorUtil.tpsColor(this.currentTps()))) .append(Component.text(String.format("%.2f", this.currentTps()), ColorUtil.tpsColor(this.currentTps())))
.build(); .build();
@@ -41,7 +43,9 @@ public class TpsBar extends Bar {
@Override @Override
protected BossBar.Color color() { protected BossBar.Color color() {
return BossBar.Color.BLUE; return this.currentTps() >= 18
? BossBar.Color.GREEN
: this.currentTps() >= 15 ? BossBar.Color.YELLOW : BossBar.Color.RED;
} }
@Override @Override

View File

@@ -17,6 +17,7 @@ import org.jetbrains.annotations.NotNull;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Settings extends Appliance { public class Settings extends Appliance {
@@ -34,7 +35,10 @@ public class Settings extends Appliance {
ChatMentions, ChatMentions,
DoubleDoors, DoubleDoors,
KnockDoors, KnockDoors,
BorderWarning BorderWarning,
LocatorBar,
InfoBars,
CoordinateDisplay
} }
public static Settings instance() { public static Settings instance() {
@@ -58,6 +62,16 @@ public class Settings extends Appliance {
private final WeakHashMap<Player, OpenSettingsInventory> openSettingsInventories = new WeakHashMap<>(); private final WeakHashMap<Player, OpenSettingsInventory> openSettingsInventories = new WeakHashMap<>();
private final WeakHashMap<Player, List<Setting<?>>> settingsCache = new WeakHashMap<>(); private final WeakHashMap<Player, List<Setting<?>>> settingsCache = new WeakHashMap<>();
protected final Map<Class<? extends Setting<?>>, Consumer<Player>> changeListeners = new WeakHashMap<>();
public <TDataType extends Setting<?>> void addChangeListener(Class<TDataType> setting, Consumer<Player> listener) {
this.changeListeners.merge(setting, listener, Consumer::andThen);
}
public <TDataType extends Setting<?>> void invokeChangeListener(Player player, Class<TDataType> setting) {
Optional.ofNullable(this.changeListeners.get(setting))
.ifPresent(listener -> listener.accept(player));
}
private List<Setting<?>> getSettings(Player player) { private List<Setting<?>> getSettings(Player player) {
if(this.settingsCache.containsKey(player)) return this.settingsCache.get(player); if(this.settingsCache.containsKey(player)) return this.settingsCache.get(player);

View File

@@ -26,7 +26,7 @@ public abstract class Setting<TDataType> {
} }
public NamespacedKey getNamespacedKey() { public NamespacedKey getNamespacedKey() {
return new NamespacedKey(Main.instance(), this.key.name()); return new NamespacedKey(Settings.class.getSimpleName().toLowerCase(), this.key.name().toLowerCase());
} }
public Settings.Key getKey() { public Settings.Key getKey() {
@@ -34,7 +34,24 @@ public abstract class Setting<TDataType> {
} }
public void initializeFromPlayer(Player p) { public void initializeFromPlayer(Player p) {
this.fromStorage(p.getPersistentDataContainer()); PersistentDataContainer dataContainer = p.getPersistentDataContainer();
try {
this.fromStorage(dataContainer);
} catch(IllegalArgumentException e) {
Main.logger().warning(String.format(
"Could not load state of setting %s from player %s: '%s'\n Did the datatype of the setting change?",
this.getNamespacedKey(),
e.getMessage(),
p.getName()
));
dataContainer.remove(this.getNamespacedKey());
this.fromStorage(dataContainer);
Main.logger().info(String.format(
"Restoring defaults of setting %s of player %s",
this.getNamespacedKey(),
p.getName()
));
}
} }
public void triggerChange(Player p, ClickType clickType) { public void triggerChange(Player p, ClickType clickType) {
@@ -42,6 +59,7 @@ public abstract class Setting<TDataType> {
this.change(p, clickType); this.change(p, clickType);
InteractSounds.of(p).click(); InteractSounds.of(p).click();
this.toStorage(p.getPersistentDataContainer(), this.state()); this.toStorage(p.getPersistentDataContainer(), this.state());
Settings.instance().invokeChangeListener(p, this.getClass());
} }
public ItemStack buildItem() { public ItemStack buildItem() {

View File

@@ -1,4 +1,4 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiAutoTotem; package eu.mhsl.craftattack.spawn.common.appliances.security.antiAutoTotem;
import eu.mhsl.craftattack.spawn.common.appliances.tooling.acInform.AcInform; import eu.mhsl.craftattack.spawn.common.appliances.tooling.acInform.AcInform;
import eu.mhsl.craftattack.spawn.core.Main; import eu.mhsl.craftattack.spawn.core.Main;

View File

@@ -1,4 +1,4 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiAutoTotem; package eu.mhsl.craftattack.spawn.common.appliances.security.antiAutoTotem;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener; import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@@ -0,0 +1,176 @@
package eu.mhsl.craftattack.spawn.common.appliances.tooling.deviceFingerprinting;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import eu.mhsl.craftattack.spawn.core.Main;
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
import net.kyori.adventure.resource.ResourcePackInfo;
import net.kyori.adventure.resource.ResourcePackRequest;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
import org.jetbrains.annotations.NotNull;
import spark.Response;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.net.URI;
import java.util.*;
public class DeviceFingerprinting extends Appliance {
public record PackInfo(@NotNull String url, @NotNull UUID uuid, @NotNull String hash) {
private static final String failingUrl = "http://127.0.0.1:0";
public PackInfo asFailing() {
return new PackInfo(failingUrl, this.uuid, this.hash);
}
}
public enum PackStatus {
UNCACHED,
CACHED,
INVALID;
public static PackStatus fromBukkitStatus(PlayerResourcePackStatusEvent.Status status) {
return switch(status) {
case DISCARDED -> CACHED;
case FAILED_DOWNLOAD -> UNCACHED;
default -> INVALID;
};
}
}
public enum PlayerStatus {
PREPARATION,
TESTING,
FINISHED,
NEW
}
private List<PackInfo> packs;
private final Map<Player, FingerprintData> fingerprints = new WeakHashMap<>();
private final UUID basePackId = UUID.randomUUID();
@Override
public void onEnable() {
this.packs = this.readPacksFromConfig();
}
public void startFingerprinting(Player player) {
this.fingerprints.put(player, FingerprintData.create(player));
Main.logger().info(String.format("Sending base ressource-pack with id '%s' to '%s'%n", this.basePackId, player.getName()));
this.sendPack(player, new PackInfo("http://localhost:8080/api/devicefingerprinting/base.zip", this.basePackId, "3296e8bdd30b4f7cffd11c780a1dc70da2948e71"));
}
public void onPackUpdate(Player player, UUID packId, PlayerResourcePackStatusEvent.Status status) {
if(!this.fingerprints.containsKey(player)) return;
FingerprintData playerFingerprint = this.fingerprints.get(player);
if(!playerFingerprint.isInTestingOrPreparation()) return;
if(packId.equals(this.basePackId)) {
Main.logger().info(String.format("Base pack for '%s' updated: '%s'", player.getName(), status));
if(status != PlayerResourcePackStatusEvent.Status.ACCEPTED) return;
Main.logger().info(String.format("Base pack loaded successfully, sending now all packs to '%s'...", player.getName()));
playerFingerprint.setTesting();
this.packs.forEach(pack -> this.sendPack(player, pack.asFailing()));
return;
}
PackInfo pack = this.packs.stream()
.filter(packInfo -> Objects.equals(packInfo.uuid, packId))
.findAny()
.orElse(null);
if(pack == null) return;
int packIndex = this.packs.indexOf(pack);
List<PackStatus> pendingPacks = playerFingerprint.getPendingPacks();
PackStatus newPackStatus = PackStatus.fromBukkitStatus(status);
if(newPackStatus == PackStatus.INVALID) return;
pendingPacks.set(packIndex, newPackStatus);
playerFingerprint.updateFingerprint();
if(Objects.requireNonNull(playerFingerprint.getStatus()) == PlayerStatus.NEW) {
Main.logger().info(String.format("Sending fingerprint packs to Player '%s', as it is a unseen Player!", player.getName()));
this.sendNewFingerprint(player, Objects.requireNonNull(playerFingerprint.getFingerPrint()));
}
}
private void sendNewFingerprint(Player player, long fingerprintId) {
for (int i = 0; i < this.packs.size(); i++) {
if ((fingerprintId & (1L << i)) != 0) {
PackInfo pack = this.packs.get(i);
this.sendPack(player, pack);
}
}
}
public void sendPack(Player player, PackInfo pack) {
player.sendResourcePacks(
ResourcePackRequest.resourcePackRequest()
.required(true)
.packs(ResourcePackInfo.resourcePackInfo(pack.uuid, URI.create(pack.url), pack.hash))
);
}
private List<DeviceFingerprinting.PackInfo> readPacksFromConfig() {
try (InputStreamReader reader = new InputStreamReader(Objects.requireNonNull(Main.class.getResourceAsStream("/deviceFingerprinting/packs.json")))) {
Type packListType = new TypeToken<List<DeviceFingerprinting.PackInfo>>(){}.getType();
List<DeviceFingerprinting.PackInfo> packs = new Gson().fromJson(reader, packListType);
if (packs.isEmpty()) throw new IllegalStateException("No resource packs found in packs.json.");
return packs;
} catch (IOException e) {
throw new IllegalStateException("Failed to parse packs.json.", e);
}
}
@Override
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
apiBuilder.rawGet(
"base.zip",
(request, response) -> this.servePack("base.zip", response)
);
for(int i = 0; i < this.packs.size(); i++) {
int packIndex = i;
apiBuilder.rawGet(
String.format("packs/%d", i),
(request, response) -> this.servePack(String.valueOf(packIndex), response)
);
}
}
private Object servePack(String name, Response response) {
try {
String resourcePath = String.format("/deviceFingerprinting/packs/%s", name);
var inputStream = Main.class.getResourceAsStream(resourcePath);
if (inputStream == null) {
throw new IllegalStateException("Pack file not found: " + resourcePath);
}
response.header("Content-Type", "application/zip");
response.header("Content-Disposition", String.format("attachment; filename=\"pack-%s.zip\"", name));
var outputStream = response.raw().getOutputStream();
inputStream.transferTo(outputStream);
outputStream.close();
return HttpServer.nothing;
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to serve pack '%s'", name), e);
}
}
public List<PackInfo> getPacks() {
return this.packs;
}
@Override
protected @NotNull List<Listener> listeners() {
return List.of(
new PlayerJoinListener()
);
}
}

View File

@@ -0,0 +1,91 @@
package eu.mhsl.craftattack.spawn.common.appliances.tooling.deviceFingerprinting;
import eu.mhsl.craftattack.spawn.core.Main;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
class FingerprintData {
public final Player player;
private DeviceFingerprinting.PlayerStatus status;
private @Nullable Long fingerPrint;
private final List<DeviceFingerprinting.PackStatus> pendingPacks;
int packCount = Main.instance().getAppliance(DeviceFingerprinting.class).getPacks().size();
private FingerprintData(Player player) {
this.player = player;
this.status = DeviceFingerprinting.PlayerStatus.PREPARATION;
this.fingerPrint = null;
this.pendingPacks = Arrays.asList(new DeviceFingerprinting.PackStatus[this.packCount]);
}
public static FingerprintData create(Player player) {
return new FingerprintData(player);
}
public void setTesting() {
this.status = DeviceFingerprinting.PlayerStatus.TESTING;
}
public void updateFingerprint() {
long fingerPrint = 0;
for (int i = 0; i < this.pendingPacks.size(); i++) {
var status = this.pendingPacks.get(i);
if(status == null) return;
switch (status) {
case CACHED:
fingerPrint |= 1L << i;
break;
case UNCACHED:
break;
default:
return;
}
}
if(fingerPrint == 0) {
this.status = DeviceFingerprinting.PlayerStatus.NEW;
this.fingerPrint = this.createNewFingerprint();
Main.logger().info(String.format("Player %s's was marked as a new Player!", this.player.getName()));
} else {
this.status = DeviceFingerprinting.PlayerStatus.FINISHED;
this.fingerPrint = fingerPrint;
}
Main.logger().info(String.format("Player %s's fingerprint is '%s'", this.player.getName(), fingerPrint));
}
private long createNewFingerprint() {
long id = 0;
Random random = new Random();
for (int i = 0; i < this.packCount / 2; i++) {
while (true) {
int bitIndex = random.nextInt(this.packCount);
if ((id & (1L << bitIndex)) == 0) {
id |= 1L << bitIndex;
break;
}
}
}
return id;
}
public List<DeviceFingerprinting.PackStatus> getPendingPacks() {
return this.pendingPacks;
}
public DeviceFingerprinting.PlayerStatus getStatus() {
return this.status;
}
public @Nullable Long getFingerPrint() {
return this.fingerPrint;
}
public boolean isInTestingOrPreparation() {
return this.status == DeviceFingerprinting.PlayerStatus.TESTING || this.status == DeviceFingerprinting.PlayerStatus.PREPARATION;
}
}

View File

@@ -0,0 +1,22 @@
package eu.mhsl.craftattack.spawn.common.appliances.tooling.deviceFingerprinting;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
class PlayerJoinListener extends ApplianceListener<DeviceFingerprinting> {
@EventHandler
public void onJoin(PlayerJoinEvent event) {
this.getAppliance().startFingerprinting(event.getPlayer());
}
@EventHandler
public void onResourcePackEvent(PlayerResourcePackStatusEvent event) {
this.getAppliance().onPackUpdate(
event.getPlayer(),
event.getID(),
event.getStatus()
);
}
}

View File

@@ -19,6 +19,7 @@ class KickCommand extends ApplianceCommand<Kick> {
@Override @Override
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception { 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().kick( this.getAppliance().kick(
args[0], args[0],
Arrays.stream(args).skip(1).collect(Collectors.joining(" ")) Arrays.stream(args).skip(1).collect(Collectors.joining(" "))

View File

@@ -0,0 +1,5 @@
## Files originally from "TrackPack"
https://github.com/ALaggyDev/TrackPack/blob/main/README.md
Discovered by: [Laggy](https://github.com/ALaggyDev/) and [NikOverflow](https://github.com/NikOverflow)

View File

@@ -0,0 +1,33 @@
import zipfile
import hashlib
import uuid
import json
SERVER_URL = "http://localhost:8080/api/devicefingerprinting"
packs = []
def file_sha1(path):
h = hashlib.sha1()
with open(path, "rb") as f:
for chunk in iter(lambda: f.read(8192), b""):
h.update(chunk)
return h.hexdigest()
for i in range(0, 24):
path = f"packs/{i}"
with zipfile.ZipFile(path, mode="w") as zf:
zf.writestr(
"pack.mcmeta",
'{"pack":{"pack_format":22,"supported_formats":[22,1000],"description":"pack ' + str(i) + '"}}',
)
hash = file_sha1(path)
packs.append({
"url": f"{SERVER_URL}/packs/{i}",
"uuid": str(uuid.uuid4()),
"hash": hash
})
with open("packs.json", "w") as f:
json.dump(packs, f, indent=4)

View File

@@ -0,0 +1,122 @@
[
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/0",
"uuid": "b35f6e2f-1b50-4493-85be-fb18bd90f9bb",
"hash": "7a39af839ea6484431f7b707759546bea991d435"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/1",
"uuid": "71095b62-d5ef-4ab2-ba3b-3c1b403f5e34",
"hash": "a9192ee73df1c5cff2c188fac6e9e638a1e7b6ce"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/2",
"uuid": "a4dba0a2-f8f2-4a81-bbb2-a9a818820330",
"hash": "6b85b0eb54865dae70bbda89746d83717dc2a214"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/3",
"uuid": "79fa2dc4-8c84-45fc-a09f-d89906f0d900",
"hash": "c7abf7a316f7e8c98985e8317a8b649e824e9f79"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/4",
"uuid": "15702c9b-a22b-426d-b48a-3d65b0368e9a",
"hash": "10cd0e2c46f192deb87ac75c149827d44a713017"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/5",
"uuid": "3d702d41-8e2f-4920-8dd0-1fd2146da9fb",
"hash": "8ad517d259e800b88a38ff00ee6721d5656822f2"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/6",
"uuid": "c20a2e47-ef43-49da-a80d-adf238df3695",
"hash": "798677405a4fd678892e1cf55585c8c91f82e1e2"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/7",
"uuid": "7ce51b81-1263-4919-9f4e-bb749ffe6e2e",
"hash": "af473b8eb7572f35d307bede5f2e20f263c0d804"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/8",
"uuid": "0c70d586-fe48-4ffc-86b0-6b9ec3bfe045",
"hash": "2fb698ff88f2436637641f3b2e6792201feb5144"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/9",
"uuid": "c7af75a8-0b72-495d-a0ff-c1c40e229c13",
"hash": "cf660460798eecf451d639873cc1fedc4661db1b"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/10",
"uuid": "248dbce6-4b2a-44b5-b038-8d718b0ced99",
"hash": "a8ebe708d0f3747c76e4e5e68db5dcb561922706"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/11",
"uuid": "10979174-cb02-40eb-a754-275551ad608d",
"hash": "54961b48db1582a1a0981c8cc9be5ae0f3122cf3"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/12",
"uuid": "a361cfa7-674c-4493-a4cf-4baff851f276",
"hash": "013719dc8da79c96b45a1c5319c20bffe1a56cc9"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/13",
"uuid": "24b39bdb-ada9-40ec-9e3a-132c74b81dc6",
"hash": "206898c6b6600d2648b2d79c61fc6255b19587d9"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/14",
"uuid": "158fc5b4-be2c-4f7a-98cb-af5993adcc90",
"hash": "061b266a7c526fb3a3152a4ea70ca5592e0b503c"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/15",
"uuid": "4f9097a7-be02-48ad-919c-f292307f8490",
"hash": "45a667a0fe06246defabca14ef1271fb6db5a1ac"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/16",
"uuid": "3ce31e60-7e8a-4fb1-8c6d-da9065bea798",
"hash": "75bb12e46203d49e89aa9a826d267552372758bc"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/17",
"uuid": "cd978e5c-3de0-4ada-8ec5-3a88a305eec6",
"hash": "5b20261f7be03e83e9c52307f1408b0c5e58358c"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/18",
"uuid": "75001e58-3999-4779-a1d1-43ab161770ce",
"hash": "544420cffb6c17113c06fb49eeba892c208719d3"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/19",
"uuid": "6a7005a9-c2ca-476d-9a12-07d120ee121a",
"hash": "fcc066a4d3193b60b102e3d906ad8dc0b0fcf65b"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/20",
"uuid": "521c0d84-d82e-49ef-b096-d9b90f15aa19",
"hash": "4545835983ec7f07d02675a69181a80dc396f038"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/21",
"uuid": "c1b590c5-43fc-41e3-83c0-47f35b14f845",
"hash": "8d4c670eaefc0482734e839b72758226dde13bc3"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/22",
"uuid": "43958a18-c087-4f2b-a6ea-066231606eb1",
"hash": "004282602f7bdbb7cd7724f23aae23876f224092"
},
{
"url": "http://localhost:8080/api/devicefingerprinting/packs/23",
"uuid": "4b91ac81-9de4-4c2b-a876-47e621496d10",
"hash": "dae68eae109e08ea4c4c943905502eb331939f64"
}
]

View File

@@ -0,0 +1 @@
!base.zip

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +1,5 @@
dependencies { dependencies {
compileOnly 'io.papermc.paper:paper-api:1.21.7-R0.1-SNAPSHOT' compileOnly 'io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT'
compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT' compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT'
implementation 'org.apache.httpcomponents:httpclient:4.5.14' implementation 'org.apache.httpcomponents:httpclient:4.5.14'
implementation 'com.sparkjava:spark-core:2.9.4' implementation 'com.sparkjava:spark-core:2.9.4'

View File

@@ -7,6 +7,7 @@ import org.bukkit.configuration.ConfigurationSection;
import spark.Request; import spark.Request;
import spark.Spark; import spark.Spark;
import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
@@ -43,12 +44,16 @@ public class HttpServer {
this.applianceName = appliance.getClass().getSimpleName().toLowerCase(); this.applianceName = appliance.getClass().getSimpleName().toLowerCase();
} }
public void rawGet(String path, BiFunction<Request, spark.Response, Object> onCall) {
Spark.get(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req, resp)));
}
public void get(String path, Function<Request, Object> onCall) { public void get(String path, Function<Request, Object> onCall) {
Spark.get(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req))); Spark.get(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req)));
} }
public void rawPost(String path, Function<Request, Object> onCall) { public void rawPost(String path, BiFunction<Request, spark.Response, Object> onCall) {
Spark.post(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req))); Spark.post(this.buildRoute(path), (req, resp) -> this.process(() -> onCall.apply(req, resp)));
} }
public <TRequest> void post(String path, Class<TRequest> clazz, RequestProvider<TRequest, Request, Object> onCall) { public <TRequest> void post(String path, Class<TRequest> clazz, RequestProvider<TRequest, Request, Object> onCall) {

View File

@@ -8,4 +8,10 @@ public class NumberUtil {
return out; return out;
} }
public static <T extends Comparable<T>> T clamp(T value, T min, T max) {
if (value.compareTo(min) < 0) return min;
if (value.compareTo(max) > 0) return max;
return value;
}
} }

View File

@@ -1,5 +1,7 @@
package eu.mhsl.craftattack.spawn.core.util.text; package eu.mhsl.craftattack.spawn.core.util.text;
import org.bukkit.Location;
public class DataSizeConverter { public class DataSizeConverter {
public static String convertBytesPerSecond(long bytes) { public static String convertBytesPerSecond(long bytes) {
double kbits = bytes * 8.0 / 1000.0; double kbits = bytes * 8.0 / 1000.0;
@@ -52,4 +54,27 @@ public class DataSizeConverter {
return String.format("%dd %dh %dm %ds", days, hours, minutes, seconds); return String.format("%dd %dh %dm %ds", days, hours, minutes, seconds);
} }
public static String getCardinalDirection(Location location) {
float yaw = location.getYaw();
yaw = (yaw % 360 + 360) % 360;
if (yaw >= 337.5 || yaw < 22.5) {
return "S";
} else if (yaw >= 22.5 && yaw < 67.5) {
return "SW";
} else if (yaw >= 67.5 && yaw < 112.5) {
return "W";
} else if (yaw >= 112.5 && yaw < 157.5) {
return "NW";
} else if (yaw >= 157.5 && yaw < 202.5) {
return "N";
} else if (yaw >= 202.5 && yaw < 247.5) {
return "NO";
} else if (yaw >= 247.5 && yaw < 292.5) {
return "O";
} else {
return "SO";
}
}
} }

View File

@@ -0,0 +1,14 @@
package eu.mhsl.craftattack.spawn.core.util.world;
import org.bukkit.World;
public class WorldUtils {
public static String getGameTime(World world) {
long timeOfDay = world.getTime() % 24000;
int hours = (int) ((timeOfDay / 1000 + 6) % 24);
int minutes = (int) ((timeOfDay % 1000) * 60 / 1000);
return String.format("%02d:%02d", hours, minutes);
}
}

View File

@@ -2,7 +2,7 @@ dependencies {
implementation project(':core') implementation project(':core')
implementation project(':common') implementation project(':common')
compileOnly 'io.papermc.paper:paper-api:1.21.7-R0.1-SNAPSHOT' compileOnly 'io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT'
compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT' compileOnly 'org.geysermc.floodgate:api:2.2.4-SNAPSHOT'
implementation 'org.apache.httpcomponents:httpclient:4.5.14' implementation 'org.apache.httpcomponents:httpclient:4.5.14'
implementation 'com.sparkjava:spark-core:2.9.4' implementation 'com.sparkjava:spark-core:2.9.4'

View File

@@ -14,6 +14,11 @@ import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
public class AntiSignEdit extends Appliance { public class AntiSignEdit extends Appliance {
private final Component disallowMessage = Component.text(
"Nutze /settings um das Bearbeiten von Schildern zu aktivieren!",
NamedTextColor.RED
);
@Override @Override
public void onEnable() { public void onEnable() {
Settings.instance().declareSetting(SignEditSetting.class); Settings.instance().declareSetting(SignEditSetting.class);
@@ -22,8 +27,9 @@ public class AntiSignEdit extends Appliance {
public boolean preventSignEdit(Player p, SignSide sign) { public boolean preventSignEdit(Player p, SignSide sign) {
SelectSetting.Options.Option setting = Settings.instance().getSetting(p, Settings.Key.SignEdit, SelectSetting.Options.Option.class); SelectSetting.Options.Option setting = Settings.instance().getSetting(p, Settings.Key.SignEdit, SelectSetting.Options.Option.class);
if(setting.is(SignEditSetting.editable)) return false; if(setting.is(SignEditSetting.editable)) return false;
if(setting.is(SignEditSetting.readOnly)) { if(setting.is(SignEditSetting.readOnly)) {
p.sendActionBar(Component.text("Das Bearbeiten von Schildern ist in deinen Einstellungen deaktiviert.", NamedTextColor.RED)); p.sendActionBar(this.disallowMessage);
return true; return true;
} }
@@ -32,7 +38,7 @@ public class AntiSignEdit extends Appliance {
.anyMatch(line -> !PlainTextComponentSerializer.plainText().serialize(line).isBlank()); .anyMatch(line -> !PlainTextComponentSerializer.plainText().serialize(line).isBlank());
if(hasText) { if(hasText) {
p.sendActionBar(Component.text("Das Bearbeiten von Schildern, welch bereits beschrieben sind, ist bei dir deaktiviert.", NamedTextColor.RED)); p.sendActionBar(this.disallowMessage);
return true; return true;
} }
} }

View File

@@ -28,7 +28,7 @@ public class DoubleDoorSetting extends BoolSetting implements CategorizedSetting
@Override @Override
protected Boolean defaultValue() { protected Boolean defaultValue() {
return false; return true;
} }
@Override @Override

View File

@@ -45,6 +45,6 @@ public class KnockDoorSetting extends SelectSetting implements CategorizedSettin
@Override @Override
protected Options.Option defaultValue() { protected Options.Option defaultValue() {
return disabled; return knockThreeTimes;
} }
} }

View File

@@ -0,0 +1,50 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.locatorBar;
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Objects;
public class LocatorBar extends Appliance {
private enum Distance {
MAX(6.0e7),
ZERO(0.0);
final double distance;
Distance(double distance) {
this.distance = distance;
}
}
@Override
public void onEnable() {
Settings.instance().declareSetting(LocatorBarSettings.class);
Settings.instance().addChangeListener(LocatorBarSettings.class, this::updateLocatorBar);
}
public void updateLocatorBar(Player player) {
boolean enabled = Settings.instance().getSetting(player, Settings.Key.LocatorBar, Boolean.class);
AttributeInstance receive = player.getAttribute(Attribute.WAYPOINT_RECEIVE_RANGE);
AttributeInstance transmit = player.getAttribute(Attribute.WAYPOINT_TRANSMIT_RANGE);
Objects.requireNonNull(receive);
Objects.requireNonNull(transmit);
receive.setBaseValue(enabled ? Distance.MAX.distance : Distance.ZERO.distance);
transmit.setBaseValue(enabled ? Distance.MAX.distance : Distance.ZERO.distance);
}
@Override
protected @NotNull List<Listener> listeners() {
return List.of(
new LocatorBarUpdateListener()
);
}
}

View File

@@ -0,0 +1,38 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.locatorBar;
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 org.bukkit.Material;
public class LocatorBarSettings extends BoolSetting implements CategorizedSetting {
@Override
public SettingCategory category() {
return SettingCategory.Gameplay;
}
public LocatorBarSettings() {
super(Settings.Key.LocatorBar);
}
@Override
protected String title() {
return "Ortungsleiste / Locator Bar";
}
@Override
protected String description() {
return "Konfiguriere, ob andere Spieler deine Position und du die Position anderer sehen möchtest";
}
@Override
protected Material icon() {
return Material.COMPASS;
}
@Override
protected Boolean defaultValue() {
return true;
}
}

View File

@@ -0,0 +1,12 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.locatorBar;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
class LocatorBarUpdateListener extends ApplianceListener<LocatorBar> {
@EventHandler
public void onJoin(PlayerJoinEvent event) {
this.getAppliance().updateLocatorBar(event.getPlayer());
}
}

View File

@@ -8,6 +8,7 @@ import eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.whitelist.Whitel
import eu.mhsl.craftattack.spawn.core.config.Configuration; import eu.mhsl.craftattack.spawn.core.config.Configuration;
import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo; import eu.mhsl.craftattack.spawn.core.util.text.DisconnectInfo;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -48,6 +49,29 @@ 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 FORCED -> Component.text("Du darfst zurzeit deinen Vogelfreistatus nicht ändern, da dieser als Strafe auferlegt wurde!");
};
String command = String.format("/%s confirm", OutlawedCommand.commandName);
Component changeText = Component.text(
String.format(
"Zum ändern deines Vogelfrei status klicke auf diese Nachricht oder tippe '%s'",
command
),
NamedTextColor.GOLD
).clickEvent(ClickEvent.suggestCommand(command));
player.sendMessage(
Component.text()
.append(confirmationMessage.color(NamedTextColor.RED))
.appendNewline()
.append(changeText)
);
}
void switchLawStatus(Player player) throws OutlawChangeNotPermitted { void switchLawStatus(Player player) throws OutlawChangeNotPermitted {
if(this.getLawStatus(player).equals(Status.FORCED)) { 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 Vogelfreistatus wurde als Strafe auferlegt und kann daher nicht verändert werden.");
@@ -103,7 +127,7 @@ public class Outlawed extends Appliance implements DisplayName.Prefixed {
public Component getStatusDescription(Status status) { public Component getStatusDescription(Status status) {
return switch(status) { return switch(status) {
case DISABLED -> Component.text("Vogelfreistatus inaktiv: ", NamedTextColor.GREEN) case DISABLED -> Component.text("Vogelfreistatus inaktiv: ", NamedTextColor.GREEN)
.append(Component.text("Es gelten die Standard Regeln!", NamedTextColor.GOLD)); .append(Component.text("Es gelten die normalen Regeln!", NamedTextColor.GOLD));
case VOLUNTARILY, FORCED -> Component.text("Vogelfreistatus aktiv: ", NamedTextColor.RED) case VOLUNTARILY, FORCED -> Component.text("Vogelfreistatus aktiv: ", NamedTextColor.RED)
.append(Component.text("Du darfst von jedem angegriffen und getötet werden!", NamedTextColor.GOLD)); .append(Component.text("Du darfst von jedem angegriffen und getötet werden!", NamedTextColor.GOLD));

View File

@@ -8,20 +8,23 @@ import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
class OutlawedCommand extends ApplianceCommand.PlayerChecked<Outlawed> { class OutlawedCommand extends ApplianceCommand.PlayerChecked<Outlawed> {
public static final String commandName = "vogelfrei";
public OutlawedCommand() { public OutlawedCommand() {
super("vogelfrei"); super(commandName);
} }
@Override @Override
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception { protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
try { if(args.length == 1 && args[0].equals("confirm")) {
this.getAppliance().switchLawStatus(this.getPlayer()); try {
sender.sendMessage( this.getAppliance().switchLawStatus(this.getPlayer());
this.getAppliance() sender.sendMessage(this.getAppliance().getStatusDescription(this.getAppliance().getLawStatus(this.getPlayer())));
.getStatusDescription(this.getAppliance().getLawStatus(this.getPlayer())) } catch(OutlawChangeNotPermitted e) {
); sender.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED));
} catch(OutlawChangeNotPermitted e) { }
sender.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED)); } else {
this.getAppliance().askForConfirmation(this.getPlayer());
} }
} }
} }

View File

@@ -17,9 +17,9 @@ public class VaroRank extends Appliance implements DisplayName.Prefixed {
private List<UUID> winners = new ArrayList<>(); private List<UUID> winners = new ArrayList<>();
private List<UUID> mostKills = new ArrayList<>(); private List<UUID> mostKills = new ArrayList<>();
private final Component winnerBadge = Component.text("\uD83D\uDC51", NamedTextColor.YELLOW) private final Component winnerBadge = Component.text("\uD83D\uDC51", NamedTextColor.GOLD)
.hoverEvent(HoverEvent.showText(Component.text("Hat zusammen mit seinem Team Varo gewonnen"))); .hoverEvent(HoverEvent.showText(Component.text("Hat zusammen mit seinem Team Varo gewonnen")));
private final Component killBadge = Component.text("\uD83D\uDDE1", NamedTextColor.RED) private final Component killBadge = Component.text("\uD83D\uDDE1", NamedTextColor.GOLD)
.hoverEvent(HoverEvent.showText(Component.text("Hat zusammen mit seinem Team die meisten Kills in Varo"))); .hoverEvent(HoverEvent.showText(Component.text("Hat zusammen mit seinem Team die meisten Kills in Varo")));
public VaroRank() { public VaroRank() {

View File

@@ -0,0 +1,350 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief;
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.NumberUtil;
import eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.commands.AntiGriefCommand;
import eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.listener.*;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.util.Ticks;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static net.kyori.adventure.text.Component.text;
public class AntiGrief extends Appliance {
public record GriefIncident(
long timestamp,
UUID worldId,
int x,
int y,
int z,
String event,
String data,
Severity severity
) {
public GriefIncident(Location loc, Event event, @Nullable Object data, Severity severity) {
this(
System.currentTimeMillis(),
loc.getWorld().getUID(),
loc.getBlockX(),
loc.getBlockY(),
loc.getBlockZ(),
event.getEventName(),
String.valueOf(data),
severity
);
}
public enum Severity {
/**
* No direct severity, but possible beginning of an incident
*/
INFO(0.5f),
/**
* Direct interaction which can lead to damage
*/
LIGHT(1),
/**
* Direkt interaction which can spread to severe incidents
*/
MODERATE(3),
/**
* Direct and most likely harmful interaction
*/
SEVERE(5);
public final float weight;
Severity(float weight) {
this.weight = weight;
}
}
}
public static final class AreaState {
public final UUID worldId;
public final int chunkX, chunkZ;
/** Rolling bucket scores for Spike Detection. */
public final NavigableMap<Long, Double> scores = new ConcurrentSkipListMap<>();
/** Incidents per Bucket */
public final Map<Long, List<GriefIncident>> incidentsByBucket = new ConcurrentHashMap<>();
public volatile double ema = 0.0;
public volatile long lastAlertAt = 0L;
AreaState(UUID worldId, int chunkX, int chunkZ) {
this.worldId = worldId;
this.chunkX = chunkX;
this.chunkZ = chunkZ;
}
public long getInhabitedTime() {
return Objects.requireNonNull(Bukkit.getWorld(this.worldId))
.getChunkAt(this.chunkX, this.chunkX).getInhabitedTime();
}
void addIncident(GriefIncident incident) {
long b = incident.timestamp / BUCKET_DURATION_MS;
this.scores.merge(b, (double) incident.severity.weight, Double::sum);
this.incidentsByBucket
.computeIfAbsent(b, k -> Collections.synchronizedList(new ArrayList<>()))
.add(incident);
}
double currentScore(long bucketIdx) {
return this.scores.getOrDefault(bucketIdx, 0.0);
}
void prune(long bucket) {
long oldest = bucket - BUCKETS_PER_CHUNK;
this.scores.headMap(oldest, true).clear();
this.incidentsByBucket.keySet().removeIf(b -> b < oldest);
}
boolean isEmpty() {
return this.scores.isEmpty() && this.incidentsByBucket.isEmpty();
}
}
/** Duration of a time bucket in milliseconds. */
private static final long BUCKET_DURATION_MS = 60 * 1000;
/** Number of buckets kept in memory per area. Defines analysis window length. */
private static final int BUCKETS_PER_CHUNK = 30;
/** Maximum retention time for individual incidents in milliseconds. */
private static final long INCIDENT_RETAIN_MS = 60 * 60 * 1000;
/** Spike factor against EMA baseline. Triggers if current score >= baseline * FACTOR_SPIKE. */
private static final double FACTOR_SPIKE = 5.0;
/** Absolute threshold for spike detection. Triggers if current score exceeds this value. */
private static final double HARD_THRESHOLD = 50.0;
/** Cooldown time in ms to suppress repeated alerts for the same area. */
private static final long ALERT_COOLDOWN_MS = 2 * 60 * 1000;
/** Smoothing factor for EMA baseline. Lower = smoother, higher = more reactive. 0.0 < EMA_ALPHA <= 1.0 */
private static final double EMA_ALPHA = 0.2;
/** Minimal chunk inhabited time to start registering scores linearly to INHABITED_FULL_MS */
private static final int INHABITED_MIN_MS = 60 * 60 * 1000;
/** Max time to reach 100% effect on the score */
private static final int INHABITED_FULL_MS = 24 * 60 * 60 * 1000;
/** Stores direct incidents mapped by player UUID. */
private final Map<UUID, Set<GriefIncident>> directGriefRegistry = new ConcurrentHashMap<>();
/** Stores passive incidents mapped by chunk key. */
private final Map<Long, Set<GriefIncident>> passiveGriefRegistry = new ConcurrentHashMap<>();
/** Stores scores by area */
private final Map<Long, AreaState> areas = new ConcurrentHashMap<>();
public void trackDirect(Player player, GriefIncident incident) {
this.directGriefRegistry
.computeIfAbsent(player.getUniqueId(), uuid -> ConcurrentHashMap.newKeySet())
.add(incident);
this.trackPassive(player.getLocation().getChunk(), incident);
}
public void trackPassive(Chunk chunk, GriefIncident incident) {
this.passiveGriefRegistry
.computeIfAbsent(chunk.getChunkKey(), aLong -> ConcurrentHashMap.newKeySet())
.add(incident);
final long areaKey = this.packArea(incident.worldId, chunk.getX(), chunk.getZ());
this.areas
.computeIfAbsent(areaKey, key -> new AreaState(incident.worldId, chunk.getX(), chunk.getZ()))
.addIncident(incident);
}
@Override
public void onEnable() {
Bukkit.getScheduler().runTaskTimerAsynchronously(Main.instance(), () -> {
final long now = System.currentTimeMillis();
final long bucketIdx = this.bucketIdx(now);
this.areas.forEach((areaKey, state) -> {
final double currentScore = state.currentScore(bucketIdx);
if (currentScore <= 0.0) return;
final double adjustedScore = adjustScoreToInhabitantTime(state, currentScore);
if (adjustedScore <= 0.0) return;
final double base = (state.ema == 0.0) ? adjustedScore : state.ema;
final double newBase = EMA_ALPHA * adjustedScore + (1 - EMA_ALPHA) * base;
state.ema = Math.max(3, newBase);
final boolean spike = adjustedScore >= HARD_THRESHOLD || adjustedScore >= base * FACTOR_SPIKE;
if (spike && (now - state.lastAlertAt) >= ALERT_COOLDOWN_MS) {
state.lastAlertAt = now;
Bukkit.getScheduler().runTask(Main.instance(), () ->
this.alertAdmins(areaKey, bucketIdx, adjustedScore, newBase)
);
}
});
}, Ticks.TICKS_PER_SECOND, Ticks.TICKS_PER_SECOND);
Bukkit.getScheduler().runTaskTimerAsynchronously(Main.instance(), () -> {
final long cutoff = System.currentTimeMillis() - INCIDENT_RETAIN_MS;
final long nowBucket = this.bucketIdx(System.currentTimeMillis());
this.directGriefRegistry.entrySet().removeIf(e -> {
e.getValue().removeIf(inc -> inc.timestamp < cutoff);
return e.getValue().isEmpty();
});
this.passiveGriefRegistry.entrySet().removeIf(e -> {
e.getValue().removeIf(inc -> inc.timestamp < cutoff);
return e.getValue().isEmpty();
});
this.areas.entrySet().removeIf(en -> {
AreaState state = en.getValue();
state.prune(nowBucket);
return state.isEmpty();
});
}, Ticks.TICKS_PER_SECOND * 30, Ticks.TICKS_PER_SECOND * 30);
}
private static double adjustScoreToInhabitantTime(AreaState state, double currentScore) {
final long inhabitedMs = state.getInhabitedTime() * Ticks.SINGLE_TICK_DURATION_MS / Ticks.TICKS_PER_SECOND;
double factor = (double) (inhabitedMs - INHABITED_MIN_MS) / (double) (INHABITED_FULL_MS - INHABITED_MIN_MS);
factor = NumberUtil.clamp(factor, 0.0, 1.0);
return currentScore * factor;
}
private void alertAdmins(long areaKey, long bucketIdx, double curr, double baseline) {
AreaState meta = this.areas.get(areaKey);
if (meta == null) return;
int cx = meta.chunkX, cz = meta.chunkZ;
UUID worldId = meta.worldId;
World world = Bukkit.getWorld(worldId);
if (world == null) return;
int bx = (cx << 4) + 8;
int bz = (cz << 4) + 8;
int by = world.getHighestBlockYAt(bx, bz);
Location center = new Location(world, bx + 0.5, by + 1.0, bz + 0.5);
List<Player> nearest = Bukkit.getOnlinePlayers().stream()
.filter(p -> p.getWorld().equals(world))
.sorted(Comparator.comparingDouble(p -> p.getLocation().distanceSquared(center)))
.limit(3)
.collect(Collectors.toList());
String playersHover = nearest.isEmpty()
? "Keine Spieler in der Nähe"
: String.join("\n", nearest.stream()
.map(p -> String.format("- %s (%.1fm)", p.getName(), Math.sqrt(p.getLocation().distanceSquared(center))))
.toList());
List<GriefIncident> incidents = meta.incidentsByBucket.getOrDefault(bucketIdx, List.of());
String incidentsHover = incidents.isEmpty()
? "Keine Details"
: String.join("\n", incidents.stream().limit(20)
.map(i -> String.format("• %s · %s · %s", i.event, i.severity, i.data))
.toList());
Component coords = text("[" + cx + ", " + cz + "]")
.hoverEvent(HoverEvent.showText(text(
"Chunk: [" + cx + ", " + cz + "]\n" +
"Block: [" + bx + ", " + by + ", " + bz + "]\n\n" +
"Nächste Spieler:\n" + playersHover
)))
.clickEvent(ClickEvent.suggestCommand(String.format("/tp %d %d %d", bx, by, bz)));
Component incCount = text(incidents.size() + " Incidents")
.hoverEvent(HoverEvent.showText(text(incidentsHover)));
Component msg = text("Möglicher Grief in ").append(coords)
.append(text(" - score=" + String.format("%.1f", curr)))
.append(text(" base=" + String.format("%.1f", baseline)))
.append(text(" - ")).append(incCount);
Bukkit.getOnlinePlayers().stream()
.filter(p -> p.hasPermission("antigrief.alert"))
.forEach(p -> p.sendMessage(msg));
Bukkit.getConsoleSender().sendMessage(
String.format("[AntiGrief] Alert %s score=%.1f base=%.1f incidents=%d @ [%d,%d]",
world.getName(), curr, baseline, incidents.size(), cx, cz));
}
private long bucketIdx(long timestamp) {
return timestamp / AntiGrief.BUCKET_DURATION_MS;
}
private long packArea(UUID worldId, int chunkX, int chunkZ) {
long chunkKey = (((long)chunkX) << 32) ^ (chunkZ & 0xffffffffL);
return worldId.getMostSignificantBits() ^ worldId.getLeastSignificantBits() ^ chunkKey;
}
public Stream<Block> getSurroundingBlocks(Location location) {
Block center = location.getBlock();
World world = center.getWorld();
int x = center.getX();
int y = center.getY();
int z = center.getZ();
return Stream.of(
world.getBlockAt(x + 1, y, z),
world.getBlockAt(x - 1, y, z),
world.getBlockAt(x, y + 1, z),
world.getBlockAt(x, y - 1, z),
world.getBlockAt(x, y, z + 1),
world.getBlockAt(x, y, z - 1)
);
}
public @Nullable AreaState getInfoAtChunk(Chunk chunk) {
long areaKey = this.packArea(chunk.getWorld().getUID(), chunk.getX(), chunk.getZ());
return this.areas.get(areaKey);
}
public List<AreaState> getHighesScoredChunks(int limit) {
long nowBucket = this.bucketIdx(System.currentTimeMillis());
return this.areas.values().stream()
.sorted(Comparator.comparingDouble((AreaState st) -> st.currentScore(nowBucket)).reversed())
.limit(limit)
.toList();
}
@Override
protected @NotNull List<Listener> listeners() {
return List.of(
new BlockRelatedGriefListener(),
new ExplosionRelatedGriefListener(),
new FireRelatedGriefListener(),
new LiquidRelatedGriefListener(),
new EntityRelatedGriefListener()
);
}
@Override
protected @NotNull List<ApplianceCommand<?>> commands() {
return List.of(
new AntiGriefCommand()
);
}
}

View File

@@ -0,0 +1,63 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.commands;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
import eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.AntiGrief;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
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 AntiGriefCommand extends ApplianceCommand.PlayerChecked<AntiGrief> {
private final Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
public AntiGriefCommand() {
super("antiGrief");
}
@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("One argument expected");
switch(args[0]) {
case "currentChunk": {
AntiGrief.AreaState state = this.getAppliance().getInfoAtChunk(this.getPlayer().getChunk());
if(state == null) throw new Error("The current chunk does not have a Score!");
sender.sendMessage(this.areaStateDisplay(state));
sender.sendMessage(String.format("ChunkLoaded: %ds", state.getInhabitedTime() / 1000));
break;
}
case "topChunks": {
List<AntiGrief.AreaState> states = this.getAppliance().getHighesScoredChunks(10);
sender.sendMessage(Component.empty().append(
states.stream().map(state -> this.areaStateDisplay(state).appendNewline()).toList()
));
break;
}
default: throw new Error("No such option!");
}
}
private Component areaStateDisplay(AntiGrief.AreaState state) {
var object = Component.text("[\uD83D\uDCC2]", NamedTextColor.GRAY)
.append(Component.text(" - ", NamedTextColor.GOLD))
.hoverEvent(HoverEvent.showText(Component.text(this.prettyGson.toJson(state))));
var location = Component.text(String.format("[%d,%d]", state.chunkX, state.chunkZ), NamedTextColor.YELLOW)
.append(Component.text(" > ", NamedTextColor.DARK_GRAY));
int incidentCount = state.incidentsByBucket.values().stream().map(List::size).mapToInt(Integer::intValue).sum();
var total = Component.text(String.format("ema:%.2f, totalIncidents:%d", state.ema, incidentCount), NamedTextColor.GRAY);
return Component.empty().append(object, location, total);
}
@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("currentChunk", "topChunks");
return null;
}
}

View File

@@ -0,0 +1,38 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.listener;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.AntiGrief;
import org.bukkit.block.Container;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.Inventory;
import java.util.Arrays;
import java.util.Objects;
public class BlockRelatedGriefListener extends ApplianceListener<AntiGrief> {
@EventHandler
public void containerBlockBreak(BlockBreakEvent event) {
if(!(event.getBlock().getState() instanceof Container container)) return;
Inventory containerInv = container.getInventory();
if(containerInv.isEmpty()) return;
long itemCount = Arrays.stream(containerInv.getStorageContents())
.filter(Objects::nonNull)
.filter(itemStack -> !itemStack.isEmpty())
.count();
this.getAppliance().trackDirect(
event.getPlayer(),
new AntiGrief.GriefIncident(
event.getBlock().getLocation(),
event,
event.getBlock().getType(),
itemCount > containerInv.getSize() / 2
? AntiGrief.GriefIncident.Severity.SEVERE
: AntiGrief.GriefIncident.Severity.MODERATE
)
);
}
}

View File

@@ -0,0 +1,142 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.listener;
import com.destroystokyo.paper.event.entity.CreeperIgniteEvent;
import eu.mhsl.craftattack.spawn.core.Main;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.AntiGrief;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Villager;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import java.util.List;
import java.util.Set;
public class EntityRelatedGriefListener extends ApplianceListener<AntiGrief> {
@EventHandler
public void buildWither(CreatureSpawnEvent event) {
if(!event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.BUILD_WITHER)) return;
this.getAppliance().trackPassive(
event.getEntity().getLocation().getChunk(),
new AntiGrief.GriefIncident(
event.getEntity().getLocation(),
event,
event.getEntity().getType(),
AntiGrief.GriefIncident.Severity.MODERATE
)
);
}
@EventHandler
public void creeperPurposelyIgnite(CreeperIgniteEvent event) {
this.getAppliance().trackPassive(
event.getEntity().getChunk(),
new AntiGrief.GriefIncident(
event.getEntity().getLocation(),
event,
event.getEntity().getType(),
AntiGrief.GriefIncident.Severity.SEVERE
)
);
}
@EventHandler
public void villagerDeath(EntityDeathEvent event) {
if(!(event.getEntity() instanceof Villager villager)) return;
if(event.getEntity().getLastDamageCause() != null) {
EntityDamageEvent lastDamage = event.getEntity().getLastDamageCause();
List<EntityDamageEvent.DamageCause> suspiciousCauses = List.of(
EntityDamageEvent.DamageCause.FIRE,
EntityDamageEvent.DamageCause.LAVA,
EntityDamageEvent.DamageCause.PROJECTILE,
EntityDamageEvent.DamageCause.ENTITY_ATTACK,
EntityDamageEvent.DamageCause.FIRE_TICK
);
if(!suspiciousCauses.contains(lastDamage.getCause())) return;
}
this.getAppliance().trackPassive(
villager.getChunk(),
new AntiGrief.GriefIncident(
villager.getLocation(),
event,
List.of(villager.getVillagerType(), String.valueOf(villager.getLastDamageCause())),
AntiGrief.GriefIncident.Severity.LIGHT
)
);
}
@EventHandler
public void petKilled(EntityDeathEvent event) {
Set<EntityType> petEntities = Set.of(
EntityType.SNIFFER,
EntityType.WOLF,
EntityType.AXOLOTL,
EntityType.ALLAY,
EntityType.CAMEL,
EntityType.PARROT,
EntityType.CAT,
EntityType.OCELOT,
EntityType.HORSE,
EntityType.DONKEY,
EntityType.MULE,
EntityType.LLAMA,
EntityType.FOX,
EntityType.TURTLE,
EntityType.PANDA,
EntityType.GOAT,
EntityType.BEE
);
if(!petEntities.contains(event.getEntity().getType())) return;
this.getAppliance().trackPassive(
event.getEntity().getChunk(),
new AntiGrief.GriefIncident(
event.getEntity().getLocation(),
event,
event.getEntity().getType(),
event.getEntity() instanceof Tameable tameable
? tameable.isTamed() ? AntiGrief.GriefIncident.Severity.SEVERE : AntiGrief.GriefIncident.Severity.MODERATE
: AntiGrief.GriefIncident.Severity.LIGHT
)
);
}
@EventHandler
public void itemBurned(EntityDamageEvent event) {
if(!(event.getEntity() instanceof Item item)) return;
int amount = item.getItemStack().getAmount();
int half = item.getItemStack().getMaxStackSize() / 2;
if (amount < half / 2) return;
List<EntityDamageEvent.DamageCause> forbiddenCauses = List.of(
EntityDamageEvent.DamageCause.FIRE,
EntityDamageEvent.DamageCause.FIRE_TICK,
EntityDamageEvent.DamageCause.LAVA,
EntityDamageEvent.DamageCause.HOT_FLOOR,
EntityDamageEvent.DamageCause.CAMPFIRE
);
if(forbiddenCauses.contains(event.getCause())) return;
Bukkit.getScheduler().runTaskLater(Main.instance(), () -> {
if (item.isValid() || !item.isDead()) return;
this.getAppliance().trackPassive(
event.getEntity().getChunk(),
new AntiGrief.GriefIncident(
event.getEntity().getLocation(),
event,
event.getEntity().getType(),
amount > half
? AntiGrief.GriefIncident.Severity.MODERATE
: AntiGrief.GriefIncident.Severity.LIGHT
)
);
}, 1L);
}
}

View File

@@ -0,0 +1,105 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.listener;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.AntiGrief;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.minecart.ExplosiveMinecart;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.TNTPrimeEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityPlaceEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import java.util.List;
public class ExplosionRelatedGriefListener extends ApplianceListener<AntiGrief> {
@EventHandler
public void tntPlacement(BlockPlaceEvent event) {
if(!event.getBlockPlaced().getType().equals(Material.TNT)) return;
this.getAppliance().trackDirect(
event.getPlayer(),
new AntiGrief.GriefIncident(
event.getBlock().getLocation(),
event,
event.getBlock().getType(),
AntiGrief.GriefIncident.Severity.MODERATE
)
);
}
@EventHandler
public void crystalPlacement(EntityPlaceEvent event) {
if(!event.getEntityType().equals(EntityType.END_CRYSTAL)) return;
AntiGrief.GriefIncident incident = new AntiGrief.GriefIncident(
event.getEntity().getLocation(),
event,
event.getEntityType(),
AntiGrief.GriefIncident.Severity.LIGHT
);
if(event.getPlayer() != null)
this.getAppliance().trackDirect(event.getPlayer(), incident);
else
this.getAppliance().trackPassive(event.getBlock().getChunk(), incident);
}
@EventHandler
public void tntPrime(TNTPrimeEvent event) {
AntiGrief.GriefIncident incident = new AntiGrief.GriefIncident(
event.getBlock().getLocation(),
event,
List.of(event.getCause(), event.getBlock().getType()),
AntiGrief.GriefIncident.Severity.MODERATE
);
if(event.getCause().equals(TNTPrimeEvent.PrimeCause.PLAYER) && event.getPrimingEntity() instanceof Player player) {
this.getAppliance().trackDirect(player, incident);
}
this.getAppliance().trackPassive(event.getBlock().getChunk(), incident);
}
@EventHandler
public void tntMinecartPlace(VehicleCreateEvent event) {
if(!(event.getVehicle() instanceof ExplosiveMinecart minecart)) return;
this.getAppliance().trackPassive(
event.getVehicle().getChunk(),
new AntiGrief.GriefIncident(
minecart.getLocation(),
event,
minecart.getType(),
AntiGrief.GriefIncident.Severity.SEVERE
)
);
}
@EventHandler
public void entityExplosion(EntityExplodeEvent event) {
this.getAppliance().trackPassive(
event.getEntity().getChunk(),
new AntiGrief.GriefIncident(
event.getLocation(),
event,
List.of(event.getEntityType(), event.blockList().stream().map(Block::getType).distinct().toList()),
AntiGrief.GriefIncident.Severity.MODERATE
)
);
}
@EventHandler
public void blockExplosion(BlockExplodeEvent event) {
this.getAppliance().trackPassive(
event.getBlock().getChunk(),
new AntiGrief.GriefIncident(
event.getBlock().getLocation(),
event,
List.of(event.getBlock().getType(), event.getExplodedBlockState().getType()),
AntiGrief.GriefIncident.Severity.MODERATE
)
);
}
}

View File

@@ -0,0 +1,82 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.listener;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.AntiGrief;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.PistonMoveReaction;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.*;
import java.util.List;
public class FireRelatedGriefListener extends ApplianceListener<AntiGrief> {
@EventHandler
public void activeBlockIgnite(BlockPlaceEvent event) {
if(!event.getBlock().getType().equals(Material.FIRE)) return;
if(this.getAppliance().getSurroundingBlocks(event.getBlock().getLocation()).noneMatch(Block::isBurnable)) return;
this.getAppliance().trackDirect(
event.getPlayer(),
new AntiGrief.GriefIncident(
event.getBlock().getLocation(),
event,
event.getBlock().getType(),
AntiGrief.GriefIncident.Severity.MODERATE
)
);
}
@EventHandler
public void blockIgnite(BlockIgniteEvent event) {
if(!event.getBlock().isBurnable()) return;
this.getAppliance().trackPassive(
event.getBlock().getChunk(),
new AntiGrief.GriefIncident(
event.getBlock().getLocation(),
event,
List.of(event.getBlock().getType(), event.getCause()),
event.getCause().equals(BlockIgniteEvent.IgniteCause.FLINT_AND_STEEL)
? AntiGrief.GriefIncident.Severity.MODERATE
: AntiGrief.GriefIncident.Severity.LIGHT
)
);
}
@EventHandler
public void fireSpread(BlockSpreadEvent event) {
if(!event.getBlock().getType().equals(Material.FIRE)) return;
this.getAppliance().trackPassive(
event.getBlock().getChunk(),
new AntiGrief.GriefIncident(
event.getBlock().getLocation(),
event,
event.getBlock().getType(),
AntiGrief.GriefIncident.Severity.LIGHT
)
);
}
@EventHandler
public void blockBurned(BlockBurnEvent event) {
if(event.getBlock().isReplaceable()) return;
if(event.getBlock().isPassable()) return;
if(event.getBlock().getPistonMoveReaction().equals(PistonMoveReaction.BREAK)) return;
if(event.getBlock().getType().name().endsWith("_LEAVES")) return;
if(event.getBlock().getType().name().endsWith("_LOG")) return;
List<Material> allowed = List.of(
Material.MOSS_BLOCK,
Material.MOSS_CARPET
);
if(allowed.contains(event.getBlock().getType())) return;
this.getAppliance().trackPassive(
event.getBlock().getChunk(),
new AntiGrief.GriefIncident(
event.getBlock().getLocation(),
event,
event.getBlock().getType(),
AntiGrief.GriefIncident.Severity.MODERATE
)
);
}
}

View File

@@ -0,0 +1,61 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.listener;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import eu.mhsl.craftattack.spawn.craftattack.appliances.security.antiGrief.AntiGrief;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class LiquidRelatedGriefListener extends ApplianceListener<AntiGrief> {
@EventHandler
public void liquidFlow(BlockFromToEvent event) {
if(event.getToBlock().isEmpty()) return;
if(event.getToBlock().isSolid()) return;
if(ThreadLocalRandom.current().nextDouble() < 0.95) return;
this.getAppliance().trackPassive(
event.getToBlock().getChunk(),
new AntiGrief.GriefIncident(
event.getToBlock().getLocation(),
event,
event.getToBlock().getType(),
AntiGrief.GriefIncident.Severity.INFO
)
);
}
@EventHandler
public void lavaCast(BlockFormEvent event) {
if(!event.getNewState().getType().equals(Material.COBBLESTONE)) return;
this.getAppliance().trackPassive(
event.getBlock().getChunk(),
new AntiGrief.GriefIncident(
event.getBlock().getLocation(),
event,
List.of(event.getBlock().getType(), event.getNewState().getType()),
AntiGrief.GriefIncident.Severity.LIGHT
)
);
}
@EventHandler
public void lavaPlace(PlayerBucketEmptyEvent event) {
if(!event.getBucket().equals(Material.LAVA_BUCKET)) return;
if(this.getAppliance().getSurroundingBlocks(event.getBlockClicked().getLocation()).noneMatch(Block::isBurnable)) return;
this.getAppliance().trackDirect(
event.getPlayer(),
new AntiGrief.GriefIncident(
event.getBlock().getLocation(),
event,
List.of(event.getBlock().getType(), event.getBucket()),
AntiGrief.GriefIncident.Severity.MODERATE
)
);
}
}

View File

@@ -0,0 +1,16 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.armadilloInfectionReducer;
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class ArmadilloInfectionReducer extends Appliance {
@Override
protected @NotNull List<Listener> listeners() {
return List.of(
new InfectionSpawnListener()
);
}
}

View File

@@ -0,0 +1,17 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.armadilloInfectionReducer;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.concurrent.ThreadLocalRandom;
class InfectionSpawnListener extends ApplianceListener<ArmadilloInfectionReducer> {
@EventHandler
public void onSpawn(CreatureSpawnEvent event) {
if(!event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.POTION_EFFECT)) return;
if(!event.getEntity().getType().equals(EntityType.SILVERFISH)) return;
if(ThreadLocalRandom.current().nextDouble() > 0.7) event.setCancelled(true);
}
}

View File

@@ -0,0 +1,16 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.endermanBlockGriefReducer;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import org.bukkit.entity.Enderman;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import java.util.concurrent.ThreadLocalRandom;
class EndermanBlockChangeListener extends ApplianceListener<EndermanBlockGriefReducer> {
@EventHandler
public void onBlockPickup(EntityChangeBlockEvent event) {
if(!(event.getEntity() instanceof Enderman)) return;
if(ThreadLocalRandom.current().nextDouble() > 0.7) event.setCancelled(true);
}
}

View File

@@ -0,0 +1,16 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.endermanBlockGriefReducer;
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class EndermanBlockGriefReducer extends Appliance {
@Override
protected @NotNull List<Listener> listeners() {
return List.of(
new EndermanBlockChangeListener()
);
}
}

View File

@@ -0,0 +1,16 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.mendingReducer;
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class MendingReducer extends Appliance {
@Override
protected @NotNull List<Listener> listeners() {
return List.of(
new MendingRepairListener()
);
}
}

View File

@@ -0,0 +1,23 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.mendingReducer;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerItemMendEvent;
public class MendingRepairListener extends ApplianceListener<MendingReducer> {
private static final double COST_MULTIPLIER = 2.0;
@EventHandler
public void onMendingRepair(PlayerItemMendEvent event) {
int baseConsumed = event.getConsumedExperience();
int orbExp = event.getExperienceOrb().getExperience();
int desiredTotal = (int) Math.ceil(baseConsumed * COST_MULTIPLIER);
int extraCost = Math.max(0, desiredTotal - baseConsumed);
int maxExtraPossible = Math.max(0, orbExp - baseConsumed);
int extraApplied = Math.min(extraCost, maxExtraPossible);
if (extraApplied > 0) event.getExperienceOrb().setExperience(orbExp - extraApplied);
}
}

View File

@@ -0,0 +1,14 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.silverfishExpReducer;
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDeathEvent;
class SilverfishDeathListener extends ApplianceListener<SilverfishExpReducer> {
@EventHandler
public void onDeath(EntityDeathEvent event) {
if(!event.getEntity().getType().equals(EntityType.SILVERFISH)) return;
event.setDroppedExp(event.getDroppedExp() / 3);
}
}

View File

@@ -0,0 +1,16 @@
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.silverfishExpReducer;
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class SilverfishExpReducer extends Appliance {
@Override
public @NotNull List<Listener> listeners() {
return List.of(
new SilverfishDeathListener()
);
}
}

View File

@@ -2,7 +2,7 @@ dependencies {
implementation project(':core') implementation project(':core')
implementation project(':common') implementation project(':common')
compileOnly 'io.papermc.paper:paper-api:1.21.7-R0.1-SNAPSHOT' compileOnly 'io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT'
implementation 'org.apache.httpcomponents:httpclient:4.5.14' implementation 'org.apache.httpcomponents:httpclient:4.5.14'
implementation 'com.sparkjava:spark-core:2.9.4' implementation 'com.sparkjava:spark-core:2.9.4'
} }