Compare commits
81 Commits
1fef363c50
...
develop-st
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a5c24235b | |||
| 62c0250049 | |||
| b4ccc3c4c8 | |||
| 78f87d97f0 | |||
| db13a9f0a2 | |||
| 09abfefe33 | |||
| bd3546abc8 | |||
| 8a7a0453ce | |||
| 64d0d817c0 | |||
| 713561bf07 | |||
| 4be3e528b1 | |||
| 53fca580f3 | |||
| 20fb4bf9fb | |||
| c42d259909 | |||
| 5c82c8d6da | |||
| 5910847172 | |||
| 7c254707c1 | |||
| 9ee5f6e419 | |||
| e49c3b1987 | |||
| 5ca4c70a41 | |||
| 040cae6cd1 | |||
| 324defc4a8 | |||
| dc0003b91e | |||
| d4a3c798f8 | |||
| c88c2ab6aa | |||
| 32a20cd4c5 | |||
| d7cc141b94 | |||
| 16d7347fd0 | |||
| fdf3b5c73f | |||
| 74f17e1b6d | |||
| 0d18b81399 | |||
| 1fa5fdfeb7 | |||
| 3bec5f4cbd | |||
| d38871eac9 | |||
| 238df2feff | |||
| e752d7f73b | |||
| b0df982be3 | |||
| dc1b5957f6 | |||
| 4068eae5bb | |||
| b1e3e99cb8 | |||
| b3787983d5 | |||
| 43ef28499b | |||
| 6e1ef4fd7c | |||
| ec2d243b7b | |||
| ef6f34c2b2 | |||
| 977f4ff4ec | |||
| 337727b0f0 | |||
| 44dae51e1c | |||
| 035864631d | |||
| f3b884058e | |||
| 03d4f4e6d8 | |||
| 7422a89d98 | |||
| 3590a5d278 | |||
| 15ac47b314 | |||
| af644a71ee | |||
| 0ce69f207f | |||
| 76297bb3af | |||
| 1aad8f07c4 | |||
| f26f4ed56a | |||
| 831eacaf47 | |||
| c71a2567bd | |||
| 72e88ce491 | |||
| 66d84f4677 | |||
| 427aed9a7e | |||
| 0d1e6070ce | |||
| 220fb9e229 | |||
| 9acac488f2 | |||
| d71c0d768e | |||
| 9ef4c2e96b | |||
| 5d33d2aff7 | |||
| 3f1065fd3a | |||
| aa868deeca | |||
| b6c298cec3 | |||
| 8f5a96dc31 | |||
| 2824c1053b | |||
| ccf383cdb5 | |||
| fce9449b7e | |||
| 69e971f618 | |||
| b1f188dece | |||
| a4289d5ac9 | |||
| 092d33beb3 |
@@ -1,7 +1,8 @@
|
||||
dependencies {
|
||||
implementation project(':core')
|
||||
|
||||
compileOnly 'io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.geysermc.floodgate:api:2.2.2-SNAPSHOT'
|
||||
compileOnly 'io.papermc.paper:paper-api:1.21.8-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'
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CraftAttackApi {
|
||||
@@ -25,4 +26,8 @@ public class CraftAttackApi {
|
||||
public static void withAuthorizationSecret(URIBuilder builder) {
|
||||
builder.addParameter("secret", apiSecret);
|
||||
}
|
||||
|
||||
public static void withAuthorizationHeader(HttpRequest.Builder builder) {
|
||||
builder.header("Authorization", apiSecret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.api;
|
||||
package eu.mhsl.craftattack.spawn.common.api;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.config.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -0,0 +1,27 @@
|
||||
package eu.mhsl.craftattack.spawn.common.api.repositories;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||
import eu.mhsl.craftattack.spawn.common.api.CraftAttackApi;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CraftAttackReportRepository extends ReportRepository {
|
||||
public CraftAttackReportRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||
}
|
||||
|
||||
public ReqResp<PlayerReports> queryReports(UUID player) {
|
||||
return this.get(
|
||||
"report",
|
||||
(parameters) -> parameters.addParameter("uuid", player.toString()),
|
||||
PlayerReports.class
|
||||
);
|
||||
}
|
||||
|
||||
public ReqResp<ReportUrl> createReport(ReportCreationInfo data) {
|
||||
return this.post(
|
||||
"report",
|
||||
data,
|
||||
ReportUrl.class
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
package eu.mhsl.craftattack.spawn.common.api.repositories;
|
||||
|
||||
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 eu.mhsl.craftattack.spawn.core.api.client.RepositoryLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ReportRepository extends HttpRepository {
|
||||
public ReportRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
||||
@RepositoryLoader.Abstraction
|
||||
public abstract class ReportRepository extends HttpRepository {
|
||||
public ReportRepository(URI basePath, RequestModifier... baseRequestModifier) {
|
||||
super(basePath, baseRequestModifier);
|
||||
}
|
||||
|
||||
public record ReportCreationInfo(@NotNull UUID reporter, @Nullable UUID reported, String reason) {
|
||||
@@ -38,20 +39,4 @@ public class ReportRepository extends HttpRepository {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ReqResp<PlayerReports> queryReports(UUID player) {
|
||||
return this.get(
|
||||
"report",
|
||||
(parameters) -> parameters.addParameter("uuid", player.toString()),
|
||||
PlayerReports.class
|
||||
);
|
||||
}
|
||||
|
||||
public ReqResp<ReportUrl> createReport(ReportCreationInfo data) {
|
||||
return this.post(
|
||||
"report",
|
||||
data,
|
||||
ReportUrl.class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package eu.mhsl.craftattack.spawn.common.api.repositories;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.api.VaroApi;
|
||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class VaroReportRepository extends ReportRepository {
|
||||
public VaroReportRepository() {
|
||||
super(VaroApi.getBaseUri(), new RequestModifier(null, VaroApi::authorizationHeader));
|
||||
}
|
||||
|
||||
public ReqResp<PlayerReports> queryReports(UUID player) {
|
||||
throw new NotImplementedException("Report querying is not supported in Varo!");
|
||||
}
|
||||
|
||||
public ReqResp<ReportUrl> createReport(ReportCreationInfo data) {
|
||||
return this.post(
|
||||
"report",
|
||||
data,
|
||||
ReportUrl.class
|
||||
);
|
||||
}
|
||||
|
||||
public record StrikeCreationInfo(
|
||||
@Nullable UUID reporter, // null for automatic creations
|
||||
@NotNull UUID reported,
|
||||
@NotNull String reason,
|
||||
@Nullable String body,
|
||||
@Nullable String notice,
|
||||
@Nullable String statement,
|
||||
int strike_reason_id // internal strike mapping
|
||||
) {
|
||||
}
|
||||
public ReqResp<Void> createStrike(StrikeCreationInfo data) {
|
||||
return this.put(
|
||||
"report",
|
||||
data,
|
||||
Void.class
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.adminMarker;
|
||||
|
||||
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 eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.displayName.DisplayName;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class AdminMarker extends Appliance implements DisplayName.Colored {
|
||||
public final static String adminPermission = "admin";
|
||||
|
||||
@Override
|
||||
public @Nullable TextColor getNameColor(Player player) {
|
||||
if(player.hasPermission(adminPermission))
|
||||
return TextColor.color(Color.AQUA.asRGB()); // TODO read permission from config
|
||||
return TextColor.color(Color.WHITE.asRGB());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||
apiBuilder.get("isAdmin", request -> {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(request.queryParams("player")));
|
||||
Main.logger().info(String.format("Adminstatus requested for %s, response: %s", player.getUniqueId(), player.isOp()));
|
||||
return player.isOp();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -21,16 +21,17 @@ 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) {
|
||||
event.joinMessage(null);
|
||||
if(event.joinMessage() == null) return;
|
||||
IteratorUtil.onlinePlayers(player -> {
|
||||
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
||||
player.sendMessage(
|
||||
@@ -43,7 +44,7 @@ class ChatMessagesListener extends ApplianceListener<ChatMessages> {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
event.quitMessage(null);
|
||||
if(event.quitMessage() == null) return;
|
||||
IteratorUtil.onlinePlayers(player -> {
|
||||
if(!Settings.instance().getSetting(player, Settings.Key.ShowJoinAndLeaveMessages, Boolean.class)) return;
|
||||
player.sendMessage(
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.time.temporal.ChronoUnit;
|
||||
public abstract class Bar {
|
||||
private BossBar bossBar;
|
||||
private final BukkitTask updateTask;
|
||||
public static String name;
|
||||
|
||||
public Bar() {
|
||||
long refreshRateInTicks = this.refresh().get(ChronoUnit.SECONDS) * Ticks.TICKS_PER_SECOND;
|
||||
@@ -32,7 +33,7 @@ public abstract class Bar {
|
||||
private BossBar createBar() {
|
||||
return BossBar.bossBar(
|
||||
this.title(),
|
||||
this.correctedProgress(),
|
||||
this.clampedProgress(),
|
||||
this.color(),
|
||||
this.overlay()
|
||||
);
|
||||
@@ -43,7 +44,7 @@ public abstract class Bar {
|
||||
|
||||
this.beforeRefresh();
|
||||
this.bossBar.name(this.title());
|
||||
this.bossBar.progress(this.correctedProgress());
|
||||
this.bossBar.progress(this.clampedProgress());
|
||||
this.bossBar.color(this.color());
|
||||
this.bossBar.overlay(this.overlay());
|
||||
}
|
||||
@@ -52,7 +53,7 @@ public abstract class Bar {
|
||||
this.updateTask.cancel();
|
||||
}
|
||||
|
||||
private float correctedProgress() {
|
||||
private float clampedProgress() {
|
||||
return Math.clamp(this.progress(), 0, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
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;
|
||||
@@ -24,39 +26,42 @@ public class InfoBars extends Appliance {
|
||||
new PlayerCounterBar()
|
||||
);
|
||||
|
||||
public void showAll(Player player) {
|
||||
this.getStoredBars(player).forEach(bar -> this.show(player, bar));
|
||||
public void showAllEnabled(Player player) {
|
||||
this.getEnabledBars(player).forEach(bar -> this.show(player, bar));
|
||||
}
|
||||
|
||||
public void hideAll(Player player) {
|
||||
this.getStoredBars(player).forEach(bar -> this.hide(player, bar));
|
||||
this.setStoredBars(player, List.of());
|
||||
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) {
|
||||
this.validateBarName(bar);
|
||||
List<String> existingBars = new ArrayList<>(this.getStoredBars(player));
|
||||
List<String> existingBars = new ArrayList<>(this.getEnabledBars(player));
|
||||
existingBars.add(bar);
|
||||
player.showBossBar(this.getBarByName(bar).getBossBar());
|
||||
this.setStoredBars(player, existingBars);
|
||||
this.setEnabledBars(player, existingBars);
|
||||
}
|
||||
|
||||
public void hide(Player player, String bar) {
|
||||
this.validateBarName(bar);
|
||||
List<String> existingBars = new ArrayList<>(this.getStoredBars(player));
|
||||
List<String> existingBars = new ArrayList<>(this.getEnabledBars(player));
|
||||
existingBars.remove(bar);
|
||||
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();
|
||||
if(!container.has(this.infoBarKey)) return List.of();
|
||||
return container.get(this.infoBarKey, PersistentDataType.LIST.strings());
|
||||
}
|
||||
|
||||
private void setStoredBars(Player player, List<String> bars) {
|
||||
player.getPersistentDataContainer().set(this.infoBarKey, PersistentDataType.LIST.strings(), bars);
|
||||
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) {
|
||||
@@ -71,8 +76,16 @@ public class InfoBars extends Appliance {
|
||||
throw new ApplianceCommand.Error(String.format("Ungültiger infobar name '%s'", name));
|
||||
}
|
||||
|
||||
public List<Bar> getInfoBars() {
|
||||
return this.infoBars;
|
||||
@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);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,9 +97,4 @@ public class InfoBars extends Appliance {
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(new ShowPreviousBarsListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||
return List.of(new InfoBarCommand());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
class ShowPreviousBarsListener extends ApplianceListener<InfoBars> {
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
// this.getAppliance().showAll(event.getPlayer());
|
||||
this.getAppliance().showAllEnabled(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import java.time.Duration;
|
||||
|
||||
public class MsptBar extends Bar {
|
||||
public static String name = "msptd";
|
||||
|
||||
@Override
|
||||
protected Duration refresh() {
|
||||
return Duration.ofSeconds(3);
|
||||
@@ -17,7 +19,7 @@ public class MsptBar extends Bar {
|
||||
|
||||
@Override
|
||||
protected String name() {
|
||||
return "mspt";
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,10 +27,10 @@ public class MsptBar extends Bar {
|
||||
return Component.text()
|
||||
.append(Component.text("M"))
|
||||
.append(Component.text("illi", NamedTextColor.GRAY))
|
||||
.append(Component.text("S"))
|
||||
.append(Component.text("econds ", NamedTextColor.GRAY))
|
||||
.append(Component.text("P"))
|
||||
.append(Component.text("er ", NamedTextColor.GRAY))
|
||||
.append(Component.text("s"))
|
||||
.append(Component.text("ekunden ", NamedTextColor.GRAY))
|
||||
.append(Component.text("p"))
|
||||
.append(Component.text("ro ", NamedTextColor.GRAY))
|
||||
.append(Component.text("T"))
|
||||
.append(Component.text("ick", NamedTextColor.GRAY))
|
||||
.append(Component.text(": "))
|
||||
@@ -43,7 +45,7 @@ public class MsptBar extends Bar {
|
||||
|
||||
@Override
|
||||
protected BossBar.Color color() {
|
||||
return BossBar.Color.BLUE;
|
||||
return this.currentMSPT() <= 50 ? BossBar.Color.GREEN : BossBar.Color.RED;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.bukkit.Bukkit;
|
||||
import java.time.Duration;
|
||||
|
||||
public class PlayerCounterBar extends Bar {
|
||||
public static String name = "playerCounter";
|
||||
|
||||
@Override
|
||||
protected Duration refresh() {
|
||||
return Duration.ofSeconds(3);
|
||||
@@ -19,7 +21,7 @@ public class PlayerCounterBar extends Bar {
|
||||
|
||||
@Override
|
||||
protected String name() {
|
||||
return "playerCounter";
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,7 +40,10 @@ public class PlayerCounterBar extends Bar {
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
@@ -10,6 +10,8 @@ import org.bukkit.Bukkit;
|
||||
import java.time.Duration;
|
||||
|
||||
public class TpsBar extends Bar {
|
||||
public static String name = "tps";
|
||||
|
||||
@Override
|
||||
protected Duration refresh() {
|
||||
return Duration.ofSeconds(3);
|
||||
@@ -17,7 +19,7 @@ public class TpsBar extends Bar {
|
||||
|
||||
@Override
|
||||
protected String name() {
|
||||
return "tps";
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,10 +27,10 @@ public class TpsBar extends Bar {
|
||||
return Component.text()
|
||||
.append(Component.text("T"))
|
||||
.append(Component.text("icks ", NamedTextColor.GRAY))
|
||||
.append(Component.text("P"))
|
||||
.append(Component.text("er ", NamedTextColor.GRAY))
|
||||
.append(Component.text("p"))
|
||||
.append(Component.text("ro ", NamedTextColor.GRAY))
|
||||
.append(Component.text("S"))
|
||||
.append(Component.text("econds", NamedTextColor.GRAY))
|
||||
.append(Component.text("ekunde", NamedTextColor.GRAY))
|
||||
.append(Component.text(": "))
|
||||
.append(Component.text(String.format("%.2f", this.currentTps()), ColorUtil.tpsColor(this.currentTps())))
|
||||
.build();
|
||||
@@ -41,7 +43,9 @@ public class TpsBar extends Bar {
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.report;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.api.repositories.ReportRepository;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.api.client.ReqResp;
|
||||
import eu.mhsl.craftattack.spawn.common.api.repositories.ReportRepository;
|
||||
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 net.kyori.adventure.text.Component;
|
||||
@@ -36,7 +37,7 @@ public class Report extends Appliance {
|
||||
}
|
||||
|
||||
public void reportToUnknown(@NotNull Player issuer) {
|
||||
ReportRepository.ReportCreationInfo request = new ReportRepository.ReportCreationInfo(issuer.getUniqueId(), null, "");
|
||||
CraftAttackReportRepository.ReportCreationInfo request = new CraftAttackReportRepository.ReportCreationInfo(issuer.getUniqueId(), null, "");
|
||||
Bukkit.getScheduler().runTaskAsynchronously(
|
||||
Main.instance(),
|
||||
() -> this.createReport(issuer, request)
|
||||
@@ -62,16 +63,17 @@ public class Report extends Appliance {
|
||||
}
|
||||
|
||||
private void createReport(Player issuer, ReportRepository.ReportCreationInfo reportRequest) {
|
||||
ReqResp<ReportRepository.ReportUrl> createdReport = this.queryRepository(ReportRepository.class)
|
||||
ReqResp<ReportRepository.ReportUrl> createdReport = this.queryRepository(CraftAttackReportRepository.class) // TODO: Besser machen!!
|
||||
.createReport(reportRequest);
|
||||
|
||||
switch(createdReport.status()) {
|
||||
case 200: // varo-endpoint specific
|
||||
case 201:
|
||||
issuer.sendMessage(
|
||||
Component.text()
|
||||
.append(Component.text("\\/".repeat(20), NamedTextColor.DARK_GRAY))
|
||||
.appendNewline()
|
||||
.append(Component.text("⚠ Der Report muss über den folgenden Link fertiggestellt werden!", NamedTextColor.GOLD))
|
||||
.append(Component.text("⚠ Der Report muss über den folgenden Link fertiggestellt werden:", NamedTextColor.GOLD))
|
||||
.appendNewline()
|
||||
.appendNewline()
|
||||
.append(
|
||||
@@ -112,7 +114,7 @@ public class Report extends Appliance {
|
||||
}
|
||||
|
||||
public void queryReports(Player issuer) {
|
||||
ReqResp<ReportRepository.PlayerReports> userReports = this.queryRepository(ReportRepository.class)
|
||||
ReqResp<ReportRepository.PlayerReports> userReports = this.queryRepository(CraftAttackReportRepository.class) // TODO: Besser machen!!
|
||||
.queryReports(issuer.getUniqueId());
|
||||
|
||||
if(userReports.status() != 200) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.datatypes.Setting;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.listeners.OpenSettingsShortcutListener;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.listeners.SettingsInventoryListener;
|
||||
import eu.mhsl.craftattack.spawn.core.util.world.InteractSounds;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -16,6 +17,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Settings extends Appliance {
|
||||
@@ -33,7 +35,10 @@ public class Settings extends Appliance {
|
||||
ChatMentions,
|
||||
DoubleDoors,
|
||||
KnockDoors,
|
||||
BorderWarning
|
||||
BorderWarning,
|
||||
LocatorBar,
|
||||
InfoBars,
|
||||
CoordinateDisplay
|
||||
}
|
||||
|
||||
public static Settings instance() {
|
||||
@@ -57,6 +62,16 @@ public class Settings extends Appliance {
|
||||
|
||||
private final WeakHashMap<Player, OpenSettingsInventory> openSettingsInventories = 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) {
|
||||
if(this.settingsCache.containsKey(player)) return this.settingsCache.get(player);
|
||||
@@ -136,6 +151,7 @@ public class Settings extends Appliance {
|
||||
}
|
||||
|
||||
player.openInventory(inventory);
|
||||
InteractSounds.of(player).open();
|
||||
this.openSettingsInventories.put(player, new OpenSettingsInventory(inventory, settings));
|
||||
}
|
||||
|
||||
@@ -166,6 +182,7 @@ public class Settings extends Appliance {
|
||||
if(!this.openSettingsInventories.containsKey(player)) return;
|
||||
this.openSettingsInventories.remove(player);
|
||||
player.updateInventory();
|
||||
InteractSounds.of(player).close();
|
||||
}
|
||||
|
||||
public boolean hasSettingsNotOpen(Player player) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.dataty
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
||||
import eu.mhsl.craftattack.spawn.core.util.text.ComponentUtil;
|
||||
import eu.mhsl.craftattack.spawn.core.util.world.InteractSounds;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
@@ -25,7 +26,7 @@ public abstract class Setting<TDataType> {
|
||||
}
|
||||
|
||||
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() {
|
||||
@@ -33,12 +34,32 @@ public abstract class Setting<TDataType> {
|
||||
}
|
||||
|
||||
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) {
|
||||
if(clickType.equals(ClickType.DOUBLE_CLICK)) return;
|
||||
this.change(p, clickType);
|
||||
InteractSounds.of(p).click();
|
||||
this.toStorage(p.getPersistentDataContainer(), this.state());
|
||||
Settings.instance().invokeChangeListener(p, this.getClass());
|
||||
}
|
||||
|
||||
public ItemStack buildItem() {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiAutoTotem;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.tooling.acInform.AcInform;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class AntiAutoTotem extends Appliance {
|
||||
|
||||
public void checkTotemUse(Player player) {
|
||||
PlayerInventory playerInv = player.getInventory();
|
||||
|
||||
Supplier<List<Material>> getHeldItems = () -> List.of(
|
||||
playerInv.getItemInMainHand().getType(),
|
||||
playerInv.getItemInOffHand().getType()
|
||||
);
|
||||
Function<Player, Boolean> isCurrentlyHoldingTotem = (p) -> getHeldItems.get().contains(Material.TOTEM_OF_UNDYING);
|
||||
|
||||
if(!isCurrentlyHoldingTotem.apply(player)) return;
|
||||
if(getHeldItems.get().stream().allMatch(material -> material.equals(Material.TOTEM_OF_UNDYING))) return;
|
||||
|
||||
AtomicInteger tickCounter = new AtomicInteger();
|
||||
Bukkit.getScheduler().runTaskTimer(
|
||||
Main.instance(),
|
||||
(task) -> {
|
||||
if(tickCounter.incrementAndGet() > 10) {
|
||||
task.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if(isCurrentlyHoldingTotem.apply(player)) {
|
||||
task.cancel();
|
||||
Main.instance().getAppliance(AcInform.class).notifyAdmins(
|
||||
"internal",
|
||||
player.getName(),
|
||||
"antiAutoTotem",
|
||||
(float) tickCounter.get()
|
||||
);
|
||||
}
|
||||
},
|
||||
1,
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new OnTotemUseListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.security.antiAutoTotem;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityResurrectEvent;
|
||||
|
||||
class OnTotemUseListener extends ApplianceListener<AntiAutoTotem> {
|
||||
@EventHandler
|
||||
public void onTotem(EntityResurrectEvent event) {
|
||||
if(event.isCancelled()) return;
|
||||
if(!(event.getEntity() instanceof Player player)) return;
|
||||
this.getAppliance().checkTotemUse(player);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ class KickCommand extends ApplianceCommand<Kick> {
|
||||
|
||||
@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().kick(
|
||||
args[0],
|
||||
Arrays.stream(args).skip(1).collect(Collectors.joining(" "))
|
||||
|
||||
@@ -9,16 +9,16 @@ import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
class PlayerLimiterListener extends ApplianceListener<PlayerLimit> {
|
||||
@EventHandler
|
||||
public void onLogin(AsyncPlayerPreLoginEvent playerPreLoginEvent) {
|
||||
playerPreLoginEvent.kickMessage(
|
||||
new DisconnectInfo(
|
||||
"Hohe Serverauslastung",
|
||||
"Der Server ist momentan an seiner Kapazitätsgrenze angelangt!",
|
||||
"Bitte versuche es zu einem späteren Zeitpunkt erneut.",
|
||||
playerPreLoginEvent.getUniqueId()
|
||||
).getComponent()
|
||||
);
|
||||
|
||||
if(Bukkit.getOnlinePlayers().size() >= this.getAppliance().getLimit())
|
||||
if(Bukkit.getOnlinePlayers().size() >= this.getAppliance().getLimit()) {
|
||||
playerPreLoginEvent.kickMessage(
|
||||
new DisconnectInfo(
|
||||
"Hohe Serverauslastung",
|
||||
"Der Server ist momentan an seiner Kapazitätsgrenze angelangt!",
|
||||
"Bitte versuche es zu einem späteren Zeitpunkt erneut.",
|
||||
playerPreLoginEvent.getUniqueId()
|
||||
).getComponent()
|
||||
);
|
||||
playerPreLoginEvent.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_FULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
dependencies {
|
||||
compileOnly 'io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.geysermc.floodgate:api:2.2.2-SNAPSHOT'
|
||||
compileOnly 'io.papermc.paper:paper-api:1.21.8-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'
|
||||
implementation 'org.reflections:reflections:0.10.2'
|
||||
|
||||
@@ -45,7 +45,20 @@ public abstract class HttpRepository extends Repository {
|
||||
.POST(HttpRequest.BodyPublishers.ofString(this.gson.toJson(data)))
|
||||
.build();
|
||||
|
||||
return this.execute(request, outputType);
|
||||
return this.execute(request, outputType, data);
|
||||
}
|
||||
|
||||
protected <TInput, TOutput> ReqResp<TOutput> put(String command, TInput data, Class<TOutput> outputType) {
|
||||
return this.put(command, parameters -> {
|
||||
}, data, outputType);
|
||||
}
|
||||
|
||||
protected <TInput, TOutput> ReqResp<TOutput> put(String command, Consumer<URIBuilder> parameters, TInput data, Class<TOutput> outputType) {
|
||||
HttpRequest request = this.getRequestBuilder(this.getUri(command, parameters))
|
||||
.PUT(HttpRequest.BodyPublishers.ofString(this.gson.toJson(data)))
|
||||
.build();
|
||||
|
||||
return this.execute(request, outputType, data);
|
||||
}
|
||||
|
||||
protected <TOutput> ReqResp<TOutput> get(String command, Class<TOutput> outputType) {
|
||||
@@ -58,7 +71,7 @@ public abstract class HttpRepository extends Repository {
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
return this.execute(request, outputType);
|
||||
return this.execute(request, outputType, null);
|
||||
}
|
||||
|
||||
private URI getUri(String command, Consumer<URIBuilder> parameters) {
|
||||
@@ -90,9 +103,14 @@ public abstract class HttpRepository extends Repository {
|
||||
return builder;
|
||||
}
|
||||
|
||||
private <TResponse> ReqResp<TResponse> execute(HttpRequest request, Class<TResponse> clazz) {
|
||||
private <TResponse> ReqResp<TResponse> execute(HttpRequest request, Class<TResponse> clazz, Object original) {
|
||||
ReqResp<String> rawResponse = this.sendHttp(request);
|
||||
Main.logger().info(String.format("HTTP-Repository fired %s, response: %s", request, rawResponse));
|
||||
Main.logger().info(String.format(
|
||||
"Request: %s\nRequest-Data: %s\nResponse: %s",
|
||||
request,
|
||||
this.gson.toJson(original),
|
||||
rawResponse
|
||||
));
|
||||
return new ReqResp<>(rawResponse.status(), this.gson.fromJson(rawResponse.data(), clazz));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.mhsl.craftattack.spawn.core.api.client;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@@ -12,7 +13,9 @@ public abstract class Repository {
|
||||
|
||||
public Repository(URI basePath) {
|
||||
this.basePath = basePath;
|
||||
this.gson = new Gson();
|
||||
this.gson = new GsonBuilder()
|
||||
.serializeNulls()
|
||||
.create();
|
||||
}
|
||||
|
||||
protected void validateThread(String commandName) {
|
||||
|
||||
@@ -8,4 +8,10 @@ public class NumberUtil {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,12 +34,12 @@ public class Countdown {
|
||||
this.onDone = onDone;
|
||||
|
||||
this.defaultAnnouncements = count -> {
|
||||
if(this.current > 60 && this.current % 60 == 0) {
|
||||
return new AnnouncementData(this.current / 60, "Minuten");
|
||||
if(count > 60 && count % 60 == 0) {
|
||||
return new AnnouncementData(count / 60, "Minuten");
|
||||
}
|
||||
|
||||
if(this.current <= 60 && (this.current <= 10 || this.current % 10 == 0)) {
|
||||
return new AnnouncementData(this.current, "Sekunden");
|
||||
if(count <= 60 && (count <= 10 || count % 10 == 0)) {
|
||||
return new AnnouncementData(count, "Sekunden");
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -87,11 +87,11 @@ public class Countdown {
|
||||
|
||||
if(this.isDone()) {
|
||||
this.onDone.run();
|
||||
this.cancel();
|
||||
this.cancelIfRunning();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
private boolean isDone() {
|
||||
return this.current <= 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package eu.mhsl.craftattack.spawn.core.util.text;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class DataSizeConverter {
|
||||
public static String convertBytesPerSecond(long bytes) {
|
||||
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);
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.mhsl.craftattack.spawn.core.util.world;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import io.papermc.paper.registry.TypedKey;
|
||||
import io.papermc.paper.registry.keys.SoundEventKeys;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -15,23 +16,30 @@ public class InteractSounds {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
private void playSound(org.bukkit.Sound sound) {
|
||||
this.player.playSound(this.getSound(sound.key()), Sound.Emitter.self());
|
||||
}
|
||||
|
||||
private Sound getSound(Key soundKey) {
|
||||
return Sound.sound(soundKey, Sound.Source.PLAYER, 1f, 1f);
|
||||
private void playSound(TypedKey<org.bukkit.Sound> sound) {
|
||||
this.player.playSound(
|
||||
Sound.sound(sound, Sound.Source.PLAYER, 1f, 1f),
|
||||
Sound.Emitter.self()
|
||||
);
|
||||
}
|
||||
|
||||
public void click() {
|
||||
this.playSound(org.bukkit.Sound.UI_BUTTON_CLICK);
|
||||
this.playSound(SoundEventKeys.UI_BUTTON_CLICK);
|
||||
}
|
||||
|
||||
public void success() {
|
||||
this.playSound(org.bukkit.Sound.ENTITY_PLAYER_LEVELUP);
|
||||
this.playSound(SoundEventKeys.ENTITY_PLAYER_LEVELUP);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
this.playSound(org.bukkit.Sound.ENTITY_SILVERFISH_DEATH);
|
||||
this.playSound(SoundEventKeys.ENTITY_SILVERFISH_DEATH);
|
||||
}
|
||||
|
||||
public void open() {
|
||||
this.playSound(SoundEventKeys.BLOCK_BARREL_OPEN);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.playSound(SoundEventKeys.BLOCK_BARREL_CLOSE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -81,3 +81,9 @@ shrinkingBorder:
|
||||
varoApi:
|
||||
endpoint: "https://mhsl.eu/varo/api"
|
||||
auth: "Basic xxx"
|
||||
|
||||
varoRank:
|
||||
winners:
|
||||
- 00000000-0000-0000-0000-000000000000
|
||||
mostKills:
|
||||
- 00000000-0000-0000-0000-000000000000
|
||||
|
||||
@@ -2,8 +2,8 @@ dependencies {
|
||||
implementation project(':core')
|
||||
implementation project(':common')
|
||||
|
||||
compileOnly 'io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.geysermc.floodgate:api:2.2.2-SNAPSHOT'
|
||||
compileOnly 'io.papermc.paper:paper-api:1.21.8-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'
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import java.util.UUID;
|
||||
|
||||
public class FeedbackRepository extends HttpRepository {
|
||||
public FeedbackRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||
}
|
||||
|
||||
public record Request(String event, List<UUID> users) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.UUID;
|
||||
|
||||
public class WhitelistRepository extends HttpRepository {
|
||||
public WhitelistRepository() {
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(CraftAttackApi::withAuthorizationSecret, null));
|
||||
super(CraftAttackApi.getBaseUri(), new RequestModifier(null, CraftAttackApi::withAuthorizationHeader));
|
||||
}
|
||||
|
||||
public record UserData(
|
||||
@@ -21,10 +21,12 @@ public class WhitelistRepository extends HttpRepository {
|
||||
) {
|
||||
}
|
||||
|
||||
private record UserQuery(UUID uuid) {}
|
||||
|
||||
public ReqResp<UserData> getUserData(UUID userId) {
|
||||
return this.get(
|
||||
"user",
|
||||
parameters -> parameters.addParameter("uuid", userId.toString()),
|
||||
return this.post(
|
||||
"player",
|
||||
new UserQuery(userId),
|
||||
UserData.class
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
public class AntiSignEdit extends Appliance {
|
||||
private final Component disallowMessage = Component.text(
|
||||
"Nutze /settings um das Bearbeiten von Schildern zu aktivieren!",
|
||||
NamedTextColor.RED
|
||||
);
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Settings.instance().declareSetting(SignEditSetting.class);
|
||||
@@ -22,8 +27,9 @@ public class AntiSignEdit extends Appliance {
|
||||
public boolean preventSignEdit(Player p, SignSide sign) {
|
||||
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.readOnly)) {
|
||||
p.sendActionBar(Component.text("Das Bearbeiten von Schildern ist in deinen Einstellungen deaktiviert.", NamedTextColor.RED));
|
||||
p.sendActionBar(this.disallowMessage);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -32,7 +38,7 @@ public class AntiSignEdit extends Appliance {
|
||||
.anyMatch(line -> !PlainTextComponentSerializer.plainText().serialize(line).isBlank());
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,5 @@ public class Advancements {
|
||||
public static String start = "start";
|
||||
public static String winner = "winner";
|
||||
public static String participateEvent = "participate_event";
|
||||
public static String ogMiner = "og_miner";
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class DoubleDoorSetting extends BoolSetting implements CategorizedSetting
|
||||
|
||||
@Override
|
||||
protected Boolean defaultValue() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.glowingBerries;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import io.papermc.paper.registry.keys.SoundEventKeys;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -23,7 +24,7 @@ public class GlowingBerries extends Appliance {
|
||||
|
||||
public void letPlayerGlow(Player player) {
|
||||
player.addPotionEffect(glowEffect);
|
||||
Sound sound = Sound.sound(org.bukkit.Sound.BLOCK_AMETHYST_BLOCK_CHIME.key(), Sound.Source.PLAYER, 1f, 1f);
|
||||
Sound sound = Sound.sound(SoundEventKeys.BLOCK_AMETHYST_BLOCK_CHIME, Sound.Source.PLAYER, 1f, 1f);
|
||||
player.stopSound(sound);
|
||||
player.playSound(sound, Sound.Emitter.self());
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class HotbarRefill extends Appliance {
|
||||
inventory.setItem(itemSlot, secondItem);
|
||||
inventory.setItem(replacementSlot, firstItem);
|
||||
|
||||
player.sendActionBar(Component.text("Die Hotbar wurde aufgefüllt", NamedTextColor.GREEN));
|
||||
player.sendActionBar(Component.text("Deine Hotbar wurde nachgefüllt \uD83D\uDCE5", NamedTextColor.GREEN));
|
||||
}, 1);
|
||||
} catch(NoSuchElementException ignored) {
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class HotbarRefillListener extends ApplianceListener<HotbarRefill> {
|
||||
ItemStack stackInHand = event.getItemInHand();
|
||||
if(stackInHand.getAmount() != 1) return;
|
||||
if(stackInHand.getType().getMaxDurability() > 0) return;
|
||||
if(stackInHand.getType().getMaxStackSize() > 0) return;
|
||||
if(stackInHand.getType().getMaxStackSize() == 1) return;
|
||||
|
||||
if(!this.getPlayerSetting(event.getPlayer()).onBlocks()) return;
|
||||
this.getAppliance().handleHotbarChange(event.getPlayer(), stackInHand);
|
||||
@@ -35,15 +35,14 @@ class HotbarRefillListener extends ApplianceListener<HotbarRefill> {
|
||||
@EventHandler
|
||||
public void onPlayerItemBreak(PlayerItemBreakEvent event) {
|
||||
if(!this.getPlayerSetting(event.getPlayer()).onTools()) return;
|
||||
|
||||
this.getAppliance().handleHotbarChange(event.getPlayer(), event.getBrokenItem());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
|
||||
if(List.of(Material.POTION, Material.HONEY_BOTTLE).contains(event.getItem().getType())) return;
|
||||
if(!this.getPlayerSetting(event.getPlayer()).onConsumable()) return;
|
||||
|
||||
if(!this.getPlayerSetting(event.getPlayer()).onConsumable()) return;
|
||||
this.getAppliance().handleHotbarChange(event.getPlayer(), event.getItem());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.ironGolemAnimation;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.entity.IronGolem;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class IronGolemAnimation extends Appliance {
|
||||
record BlockChange(Block original, BlockData fakeBlock) {}
|
||||
|
||||
public void onGolemSpawn(IronGolem golem) {
|
||||
this.modifyGolem(golem, false);
|
||||
Location golemLocation = golem.getLocation();
|
||||
|
||||
BlockData bodyBlockData = Bukkit.createBlockData(Material.IRON_BLOCK);
|
||||
BlockData headBlockData = Bukkit.createBlockData(
|
||||
Material.CARVED_PUMPKIN,
|
||||
blockData -> ((Directional) blockData).setFacing(golem.getFacing())
|
||||
);
|
||||
Vector facingVector = golem.getFacing().getDirection().rotateAroundY(Math.toRadians(90));
|
||||
Block golemCenterBlock = golemLocation.getBlock().getRelative(BlockFace.UP);
|
||||
|
||||
List<BlockChange> buildBlocks = List.of(
|
||||
new BlockChange(golemCenterBlock.getRelative(BlockFace.DOWN), bodyBlockData),
|
||||
new BlockChange(golemCenterBlock, bodyBlockData),
|
||||
new BlockChange(golemCenterBlock.getLocation().add(facingVector).getBlock(), bodyBlockData),
|
||||
new BlockChange(golemCenterBlock.getLocation().add(facingVector.multiply(-1)).getBlock(), bodyBlockData),
|
||||
new BlockChange(golemCenterBlock.getRelative(BlockFace.UP), headBlockData)
|
||||
);
|
||||
|
||||
Collection<Player> viewers = golemLocation.getNearbyPlayers(golemLocation.getWorld().getViewDistance() * 16);
|
||||
BiConsumer<Location, BlockData> changeBlockForViewers = (location, blockData) -> {
|
||||
viewers.forEach(player -> player.sendBlockChange(location, blockData));
|
||||
golem.getWorld().playSound(
|
||||
location,
|
||||
blockData.getSoundGroup().getPlaceSound(),
|
||||
SoundCategory.BLOCKS,
|
||||
1f,
|
||||
1f
|
||||
);
|
||||
};
|
||||
for(int i = 0; i < buildBlocks.size(); i++) {
|
||||
BlockChange blockChange = buildBlocks.get(i);
|
||||
Bukkit.getScheduler().runTaskLater(
|
||||
Main.instance(),
|
||||
() -> changeBlockForViewers.accept(blockChange.original.getLocation(), blockChange.fakeBlock),
|
||||
6L * i
|
||||
);
|
||||
}
|
||||
|
||||
Consumer<List<BlockChange>> restoreBlockChanges = (blocks) -> {
|
||||
buildBlocks.forEach((blockChange) -> changeBlockForViewers.accept(
|
||||
blockChange.original().getLocation(),
|
||||
blockChange.original.getBlockData()
|
||||
));
|
||||
|
||||
this.modifyGolem(golem, true);
|
||||
this.spawnEffect(buildBlocks);
|
||||
};
|
||||
Bukkit.getScheduler().runTaskLater(
|
||||
Main.instance(),
|
||||
() -> restoreBlockChanges.accept(buildBlocks),
|
||||
6L * buildBlocks.size() + 2
|
||||
);
|
||||
}
|
||||
|
||||
private void spawnEffect(List<BlockChange> buildBlocks) {
|
||||
buildBlocks.forEach((blockChange) -> {
|
||||
World world = blockChange.original.getLocation().getWorld();
|
||||
world.spawnParticle(
|
||||
Particle.BLOCK,
|
||||
blockChange.original.getLocation().add(0.5, 0.5, 0.5),
|
||||
50,
|
||||
blockChange.fakeBlock
|
||||
);
|
||||
world.playSound(
|
||||
blockChange.original.getLocation(),
|
||||
blockChange.fakeBlock.getSoundGroup().getBreakSound(),
|
||||
SoundCategory.BLOCKS,
|
||||
1f,
|
||||
1f
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public void modifyGolem(IronGolem golem, boolean setVisible) {
|
||||
golem.setInvisible(!setVisible);
|
||||
golem.setInvulnerable(!setVisible);
|
||||
golem.setAI(setVisible);
|
||||
golem.setGravity(setVisible);
|
||||
golem.setCollidable(setVisible);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new NaturalIronGolemSpawnEvent()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.ironGolemAnimation;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.entity.IronGolem;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
class NaturalIronGolemSpawnEvent extends ApplianceListener<IronGolemAnimation> {
|
||||
@EventHandler
|
||||
public void onGolemSpawn(CreatureSpawnEvent event) {
|
||||
if(!(event.getEntity() instanceof IronGolem golem)) return;
|
||||
if(event.getSpawnReason() != CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE) return;
|
||||
this.getAppliance().onGolemSpawn(golem);
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,6 @@ public class KnockDoorSetting extends SelectSetting implements CategorizedSettin
|
||||
|
||||
@Override
|
||||
protected Options.Option defaultValue() {
|
||||
return disabled;
|
||||
return knockThreeTimes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.minecartBlocks;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Minecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.vehicle.VehicleDestroyEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
class MinecartBlockChangeListener extends ApplianceListener<MinecartBlocks> {
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEntityEvent event) {
|
||||
if(!event.getPlayer().isSneaking()) return;
|
||||
if(!(event.getRightClicked() instanceof Minecart minecart)) return;
|
||||
if(!this.isBasicMinecart(minecart)) return;
|
||||
if(this.minecartContainsBlock(minecart)) return;
|
||||
|
||||
PlayerInventory playerInv = event.getPlayer().getInventory();
|
||||
Material heldBlock = playerInv.getItemInMainHand().getType();
|
||||
|
||||
if(!heldBlock.isBlock() || !heldBlock.isSolid()) return;
|
||||
if(!this.getAppliance().isAllowedMaterial(heldBlock)) return;
|
||||
|
||||
minecart.setDisplayBlockData(heldBlock.createBlockData());
|
||||
playerInv.removeItem(ItemStack.of(heldBlock));
|
||||
this.getAppliance().onBlockPut(event.getPlayer(), heldBlock);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDestroy(VehicleDestroyEvent event) {
|
||||
if(!(event.getVehicle() instanceof Minecart minecart)) return;
|
||||
if(!this.isBasicMinecart(minecart)) return;
|
||||
|
||||
Material containingMaterial = minecart.getDisplayBlockData().getMaterial();
|
||||
if(containingMaterial.equals(Material.AIR)) return;
|
||||
|
||||
Location vehicleLocation = event.getVehicle().getLocation();
|
||||
vehicleLocation.getWorld().dropItem(vehicleLocation, ItemStack.of(containingMaterial));
|
||||
minecart.setDisplayBlockData(null);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEnter(VehicleEnterEvent event) {
|
||||
if(!(event.getVehicle() instanceof Minecart minecart)) return;
|
||||
if(!this.minecartContainsBlock(minecart)) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||
private boolean isBasicMinecart(Minecart minecart) {
|
||||
return minecart.getMinecartMaterial().equals(Material.MINECART);
|
||||
}
|
||||
|
||||
private boolean minecartContainsBlock(Minecart minecart) {
|
||||
return !minecart.getDisplayBlockData().getMaterial().equals(Material.AIR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.minecartBlocks;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.customAdvancements.Advancements;
|
||||
import eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.customAdvancements.CustomAdvancements;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.Bisected;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.data.Waterlogged;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MinecartBlocks extends Appliance {
|
||||
private final List<Material> blackListedMaterials = List.of(
|
||||
Material.COMMAND_BLOCK,
|
||||
Material.FURNACE,
|
||||
Material.HOPPER,
|
||||
Material.TNT,
|
||||
Material.CHEST,
|
||||
Material.TRAPPED_CHEST
|
||||
);
|
||||
|
||||
public boolean isAllowedMaterial(Material material) {
|
||||
if(this.blackListedMaterials.contains(material)) return false;
|
||||
BlockData blockData = material.createBlockData();
|
||||
return !(
|
||||
(blockData instanceof Directional)
|
||||
|| (blockData instanceof Bisected)
|
||||
|| (blockData instanceof Waterlogged)
|
||||
);
|
||||
}
|
||||
|
||||
public void onBlockPut(Player player, Material material) {
|
||||
if(!material.name().toLowerCase().endsWith("_ore")) return;
|
||||
Main.instance().getAppliance(CustomAdvancements.class).grantAdvancement(Advancements.ogMiner, player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new MinecartBlockChangeListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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.util.text.DisconnectInfo;
|
||||
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.format.NamedTextColor;
|
||||
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 {
|
||||
if(this.getLawStatus(player).equals(Status.FORCED)) {
|
||||
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) {
|
||||
return switch(status) {
|
||||
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)
|
||||
.append(Component.text("Du darfst von jedem angegriffen und getötet werden!", NamedTextColor.GOLD));
|
||||
|
||||
@@ -8,20 +8,23 @@ import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class OutlawedCommand extends ApplianceCommand.PlayerChecked<Outlawed> {
|
||||
public static final String commandName = "vogelfrei";
|
||||
|
||||
public OutlawedCommand() {
|
||||
super("vogelfrei");
|
||||
super(commandName);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) throws Exception {
|
||||
try {
|
||||
this.getAppliance().switchLawStatus(this.getPlayer());
|
||||
sender.sendMessage(
|
||||
this.getAppliance()
|
||||
.getStatusDescription(this.getAppliance().getLawStatus(this.getPlayer()))
|
||||
);
|
||||
} catch(OutlawChangeNotPermitted e) {
|
||||
sender.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED));
|
||||
if(args.length == 1 && args[0].equals("confirm")) {
|
||||
try {
|
||||
this.getAppliance().switchLawStatus(this.getPlayer());
|
||||
sender.sendMessage(this.getAppliance().getStatusDescription(this.getAppliance().getLawStatus(this.getPlayer())));
|
||||
} catch(OutlawChangeNotPermitted e) {
|
||||
sender.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED));
|
||||
}
|
||||
} else {
|
||||
this.getAppliance().askForConfirmation(this.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.recoveryCompass;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
class KeepRecoveryCompassOnDeathListener extends ApplianceListener<RecoveryCompass> {
|
||||
@EventHandler
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
ItemStack source = event.getDrops().stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(item -> item.getType() == Material.RECOVERY_COMPASS)
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (source == null) return;
|
||||
|
||||
if (source.getAmount() > 1) {
|
||||
source.setAmount(source.getAmount() - 1);
|
||||
} else {
|
||||
event.getDrops().remove(source);
|
||||
}
|
||||
|
||||
ItemStack kept = source.clone();
|
||||
kept.setAmount(1);
|
||||
event.getItemsToKeep().add(kept);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.recoveryCompass;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
class PlayerFirstJoinCompassGift extends ApplianceListener<RecoveryCompass> {
|
||||
private final NamespacedKey alreadyGiftedKey = new NamespacedKey(this.getClass().getSimpleName().toLowerCase(), "alreadyGifted".toLowerCase());
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PersistentDataContainer container = player.getPersistentDataContainer();
|
||||
if(container.has(alreadyGiftedKey)) return;
|
||||
player.getInventory().addItem(ItemStack.of(Material.RECOVERY_COMPASS));
|
||||
container.set(alreadyGiftedKey, PersistentDataType.BOOLEAN, true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.gameplay.recoveryCompass;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RecoveryCompass extends Appliance {
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new PlayerFirstJoinCompassGift(),
|
||||
new KeepRecoveryCompassOnDeathListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.metaGameplay.adminMarker;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.displayName.DisplayName;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class AdminMarker extends Appliance implements DisplayName.Colored {
|
||||
@Override
|
||||
public @Nullable TextColor getNameColor(Player player) {
|
||||
if(player.hasPermission("chatcolor"))
|
||||
return TextColor.color(Color.AQUA.asRGB()); // TODO read permission from config
|
||||
return TextColor.color(Color.WHITE.asRGB());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.metaGameplay.varoRank;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.displayName.DisplayName;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class VaroRank extends Appliance implements DisplayName.Prefixed {
|
||||
private List<UUID> winners = new ArrayList<>();
|
||||
private List<UUID> mostKills = new ArrayList<>();
|
||||
|
||||
private final Component winnerBadge = Component.text("\uD83D\uDC51", NamedTextColor.GOLD)
|
||||
.hoverEvent(HoverEvent.showText(Component.text("Hat zusammen mit seinem Team Varo gewonnen")));
|
||||
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")));
|
||||
|
||||
public VaroRank() {
|
||||
super("varoRank");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Function<List<String>, List<UUID>> processUUIDs = list -> list.stream()
|
||||
.map(String::trim)
|
||||
.map(UUID::fromString)
|
||||
.toList();
|
||||
|
||||
this.winners = processUUIDs.apply(this.localConfig().getStringList("winners"));
|
||||
this.mostKills = processUUIDs.apply(this.localConfig().getStringList("mostKills"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Component getNamePrefix(Player player) {
|
||||
UUID playerId = player.getUniqueId();
|
||||
|
||||
boolean isWinner = this.winners.contains(playerId);
|
||||
boolean hasMostKills = this.mostKills.contains(playerId);
|
||||
|
||||
if (!isWinner && !hasMostKills) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Component.text()
|
||||
.color(NamedTextColor.GOLD)
|
||||
.append(Component.text("["))
|
||||
.append(isWinner ? this.winnerBadge : Component.empty())
|
||||
.append(hasMostKills ? this.killBadge : Component.empty())
|
||||
.append(Component.text("]"))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,6 @@ public class ProjectStart extends Appliance {
|
||||
private final Map<GameRule<Boolean>, Boolean> gameRulesAfterStart = Map.ofEntries(
|
||||
entry(GameRule.DO_DAYLIGHT_CYCLE, true),
|
||||
entry(GameRule.DO_INSOMNIA, true),
|
||||
entry(GameRule.ANNOUNCE_ADVANCEMENTS, true),
|
||||
entry(GameRule.DISABLE_RAIDS, false),
|
||||
entry(GameRule.DO_FIRE_TICK, true),
|
||||
entry(GameRule.DO_ENTITY_DROPS, true),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.tooling.spawnpoint;
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.spawnpoint;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.tooling.spawnpoint;
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.spawnpoint;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.mhsl.craftattack.spawn.common.appliances.tooling.spawnpoint;
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.spawnpoint;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
@@ -0,0 +1,51 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tooling.statistics;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.api.server.HttpServer;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Statistics extends Appliance {
|
||||
record StatisticsResponse(List<PlayerStatistics> playerStatistics) {
|
||||
record PlayerStatistics(String playerName, String playerUuid, List<MaterialStatistic> statistics) {
|
||||
}
|
||||
}
|
||||
|
||||
record MaterialStatistic(String name, String material, int value) {
|
||||
}
|
||||
|
||||
record StatisticsRequest(List<MaterialStatistic> categories) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||
apiBuilder.post(
|
||||
"getStatistics",
|
||||
StatisticsRequest.class,
|
||||
(statistics, request) -> {
|
||||
Main.instance().getLogger().info("API requested statistics");
|
||||
List<StatisticsResponse.PlayerStatistics> statisticsList = Arrays.stream(Bukkit.getOfflinePlayers())
|
||||
.parallel()
|
||||
.map(player -> new StatisticsResponse.PlayerStatistics(
|
||||
player.getName(),
|
||||
player.getUniqueId().toString(),
|
||||
statistics.categories().stream()
|
||||
.map(category -> {
|
||||
String material = (category.material() == null || category.material().isBlank()) ? null : category.material();
|
||||
return new MaterialStatistic(category.name(), material, material == null
|
||||
? player.getStatistic(Statistic.valueOf(category.name()))
|
||||
: player.getStatistic(Statistic.valueOf(category.name()), Material.valueOf(material))
|
||||
);
|
||||
})
|
||||
.toList()
|
||||
))
|
||||
.toList();
|
||||
return new StatisticsResponse(statisticsList);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class Whitelist extends Appliance {
|
||||
);
|
||||
|
||||
if(response.status() != HttpStatus.OK)
|
||||
throw new IllegalStateException(String.format("Http Reponse %d", response.status()));
|
||||
throw new IllegalStateException(String.format("Unwanted response %d!", response.status()));
|
||||
|
||||
return response.data();
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.phantomReducer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PhantomReducer extends Appliance {
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new PhantomSpawnListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package eu.mhsl.craftattack.spawn.craftattack.appliances.tweaks.phantomReducer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import org.bukkit.entity.Phantom;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
class PhantomSpawnListener extends ApplianceListener<PhantomReducer> {
|
||||
@EventHandler
|
||||
public void onPhantomSpawn(CreatureSpawnEvent event) {
|
||||
if(!(event.getEntity() instanceof Phantom)) return;
|
||||
if(ThreadLocalRandom.current().nextDouble() > 0.8) event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
);
|
||||
}
|
||||
}
|
||||
24
local.gradle.example
Normal file
24
local.gradle.example
Normal file
@@ -0,0 +1,24 @@
|
||||
tasks.register('deployVaroPlugin', Copy) {
|
||||
dependsOn ":varo:shadowJar"
|
||||
from { project(":varo").shadowJar.archivePath }
|
||||
into file('path') // path to plugins folder
|
||||
rename { fileName -> "varo.jar" }
|
||||
}
|
||||
|
||||
tasks.register("uploadVaroPlugin") {
|
||||
dependsOn(":varo:shadowJar")
|
||||
|
||||
doLast {
|
||||
def jarFile = project(":varo").tasks.named("shadowJar").get().outputs.files.singleFile
|
||||
exec {
|
||||
commandLine "scp", "-4", "-P", "22", jarFile.absolutePath, "user@host:path/varo.jar"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('deployCraftAttackPlugin', Copy) {
|
||||
dependsOn ":craftattack:shadowJar"
|
||||
from { project(":craftattack").shadowJar.archivePath }
|
||||
into file('path') // path to plugins folder
|
||||
rename { fileName -> "craftattack.jar" }
|
||||
}
|
||||
@@ -2,7 +2,7 @@ dependencies {
|
||||
implementation project(':core')
|
||||
implementation project(':common')
|
||||
|
||||
compileOnly 'io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT'
|
||||
compileOnly 'io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT'
|
||||
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
|
||||
implementation 'com.sparkjava:spark-core:2.9.4'
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package eu.mhsl.craftattack.spawn.varo.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.varo.api.VaroApi;
|
||||
import eu.mhsl.craftattack.spawn.common.api.VaroApi;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -28,7 +28,6 @@ public class TeamRepository extends HttpRepository {
|
||||
|
||||
public ReqResp<List<Team>> getTeams() {
|
||||
var resp = this.get("team", Object.class);
|
||||
System.out.println(resp.toString());
|
||||
return resp
|
||||
.convertToTypeToken(new TypeToken<List<Team>>() {}.getType())
|
||||
.cast();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.api.repositories;
|
||||
|
||||
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.VaroApi;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class VaroPlayerRepository extends HttpRepository {
|
||||
public VaroPlayerRepository() {
|
||||
super(VaroApi.getBaseUri(), new RequestModifier(null, VaroApi::authorizationHeader));
|
||||
}
|
||||
|
||||
public record VaroDeath(UUID user, @Nullable UUID killer, String message) {}
|
||||
public ReqResp<Void> registerDeath(VaroDeath death) {
|
||||
return this.post("player/death", death, Void.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks;
|
||||
|
||||
public interface Task {
|
||||
void stopTask();
|
||||
boolean isTaskRunning();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks;
|
||||
|
||||
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.varo.appliances.metaGameplay.teams.VaroTeam;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TeamTasks extends Appliance {
|
||||
public enum Type {
|
||||
/**
|
||||
* Task for kicking Team after the desired Playtime
|
||||
*/
|
||||
TIME_KICK,
|
||||
JOIN_PAIR
|
||||
}
|
||||
|
||||
private final Map<VaroTeam, Map<Type, Task>> tasks = new HashMap<>();
|
||||
|
||||
private Map<Type, Task> getTeamTasks(VaroTeam team) {
|
||||
return this.tasks.computeIfAbsent(team, varoTeam -> new HashMap<>());
|
||||
}
|
||||
|
||||
public Map<Type, Task> getRunningTeamTasks(VaroTeam team) {
|
||||
return this.getTeamTasks(team).entrySet().stream()
|
||||
.filter(entry -> entry.getValue().isTaskRunning())
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
public void cancelTeamTasks(VaroTeam team) {
|
||||
Main.logger().info(String.format("All TeamTasks for Team %s were cancelled: %s", team.name, this.getRunningTeamTasks(team)));
|
||||
this.getTeamTasks(team).forEach((type, task) -> task.stopTask());
|
||||
}
|
||||
|
||||
public void addTask(VaroTeam team, Type type, Task runnable) {
|
||||
if(this.getTeamTasks(team).containsKey(type) && this.getTeamTasks(team).get(type).isTaskRunning()) {
|
||||
throw new IllegalStateException(String.format("Task %s for Team %s was already running!", type.name(), team.name));
|
||||
}
|
||||
|
||||
this.getTeamTasks(team).put(type, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||
return List.of(new TeamTasksCommand());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.Teams;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TeamTasksCommand extends ApplianceCommand<TeamTasks> {
|
||||
public TeamTasksCommand() {
|
||||
super("teamTasks");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if(args.length < 1) throw new Error("Please specify Teamname");
|
||||
var team = Main.instance().getAppliance(Teams.class).findTeamByName(args[0]);
|
||||
if(team == null) throw new Error("Team not found!");
|
||||
var tasks = this.getAppliance().getRunningTeamTasks(team);
|
||||
if(tasks.isEmpty()) {
|
||||
sender.sendMessage("No Tasks found!");
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
tasks.entrySet()
|
||||
.stream()
|
||||
.map(entry -> String.format("%s: %s", entry.getKey().name(), entry.getValue().getClass().getSimpleName()))
|
||||
.collect(Collectors.joining("\n"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
var teams = Main.instance().getAppliance(Teams.class).getAllTeams();
|
||||
return teams.stream().map(team -> team.name).toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks.tasks;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks.Task;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public abstract class BukkitTeamTask implements Task, BukkitTask {
|
||||
@Override
|
||||
public void stopTask() {
|
||||
this.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTaskRunning() {
|
||||
return !this.isCancelled();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks.tasks;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.util.text.Countdown;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks.Task;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class CountdownTeamTask extends Countdown implements Task {
|
||||
public CountdownTeamTask(int countdownFrom, Function<AnnouncementData, Component> announcementBuilder, Consumer<Component> announcementConsumer, Runnable onDone) {
|
||||
super(countdownFrom, announcementBuilder, announcementConsumer, onDone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopTask() {
|
||||
super.cancelIfRunning();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTaskRunning() {
|
||||
return super.isRunning();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.fightDetector;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.Teams;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.VaroTeam;
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FightDetector extends Appliance {
|
||||
public static final long FIGHT_TIMEOUT = 60 * 1000;
|
||||
private static final long BLOCK_RADIUS = 30;
|
||||
|
||||
public final Map<VaroTeam, Long> fights = new HashMap<>();
|
||||
|
||||
public FightDetector() {
|
||||
Bukkit.getScheduler().runTaskTimer(
|
||||
Main.instance(),
|
||||
() -> {
|
||||
var teamFights = this.fights.keySet().stream()
|
||||
.filter(this::isInFight)
|
||||
.toList();
|
||||
if(teamFights.isEmpty()) return;
|
||||
Main.logger().info(String.format(
|
||||
"There are %d Teams in Fight: %s",
|
||||
teamFights.size(),
|
||||
teamFights.stream()
|
||||
.map(varoTeam -> String.format(
|
||||
"%s[%s]",
|
||||
varoTeam.name,
|
||||
varoTeam.members.stream()
|
||||
.map(member -> member.player.getName())
|
||||
.collect(Collectors.joining(","))))
|
||||
.collect(Collectors.joining(", "))
|
||||
));
|
||||
},
|
||||
Ticks.TICKS_PER_SECOND * 15,
|
||||
Ticks.TICKS_PER_SECOND * 15
|
||||
);
|
||||
|
||||
Bukkit.getScheduler().runTaskTimer(
|
||||
Main.instance(),
|
||||
this::detectNearbyFights,
|
||||
Ticks.TICKS_PER_SECOND,
|
||||
Ticks.TICKS_PER_SECOND
|
||||
);
|
||||
}
|
||||
|
||||
private void detectNearbyFights() {
|
||||
var players = Bukkit.getOnlinePlayers();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Main.instance(), () -> {
|
||||
for (Player player : players) {
|
||||
VaroTeam ownTeam = this.queryAppliance(Teams.class).getTeamFromPlayer(player.getUniqueId());
|
||||
if (ownTeam == null) continue;
|
||||
|
||||
for (Player otherPlayer : players) {
|
||||
if (player.equals(otherPlayer)) continue;
|
||||
|
||||
VaroTeam otherTeam = this.queryAppliance(Teams.class).getTeamFromPlayer(otherPlayer.getUniqueId());
|
||||
if (otherTeam == null || ownTeam.equals(otherTeam)) continue;
|
||||
if(!player.getLocation().getWorld().equals(otherPlayer.getLocation().getWorld())) continue;
|
||||
|
||||
if (player.getLocation().distance(otherPlayer.getLocation()) <= BLOCK_RADIUS) {
|
||||
this.setInFight(ownTeam);
|
||||
this.setInFight(otherTeam);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isInFight(VaroTeam team) {
|
||||
Long lastFightTime = this.fights.get(team);
|
||||
if(lastFightTime == null) return false;
|
||||
return (System.currentTimeMillis() - lastFightTime <= FIGHT_TIMEOUT);
|
||||
}
|
||||
|
||||
public void setInFight(VaroTeam team) {
|
||||
this.fights.put(team, System.currentTimeMillis());
|
||||
}
|
||||
public void setInFight(Player player) {
|
||||
this.setInFight(this.queryAppliance(Teams.class).getTeamFromPlayer(player.getUniqueId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<Listener> listeners() {
|
||||
return List.of(
|
||||
new FightOnInteractionListener()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.fightDetector;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceListener;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.Teams;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.VaroTeam;
|
||||
import io.papermc.paper.event.player.PrePlayerAttackEntityEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
class FightOnInteractionListener extends ApplianceListener<FightDetector> {
|
||||
@EventHandler
|
||||
public void onAttack(PrePlayerAttackEntityEvent event) {
|
||||
if(!event.willAttack()) return;
|
||||
|
||||
if(event.getAttacked() instanceof Player attackedPlayer) {
|
||||
Teams teamsAppliance = Main.instance().getAppliance(Teams.class);
|
||||
VaroTeam attacker = teamsAppliance.getTeamFromPlayer(event.getPlayer().getUniqueId());
|
||||
VaroTeam attacked = teamsAppliance.getTeamFromPlayer(event.getAttacked().getUniqueId());
|
||||
if(attacked == null) return;
|
||||
if(attacker == null) return;
|
||||
if(attacker.equals(attacked)) return;
|
||||
|
||||
this.getAppliance().setInFight(event.getPlayer());
|
||||
this.getAppliance().setInFight(attackedPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.joinProtection;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.Teams;
|
||||
import eu.mhsl.craftattack.spawn.core.util.IteratorUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.util.Ticks;
|
||||
@@ -27,15 +27,18 @@ public class JoinProtection extends Appliance {
|
||||
private final Map<UUID, Options> protectedPlayers = new HashMap<>();
|
||||
|
||||
public void addProtection(Player player) {
|
||||
if(player.isOp()) return;
|
||||
|
||||
this.protectedPlayers.put(player.getUniqueId(), new Options());
|
||||
PotionEffect resistance = new PotionEffect(PotionEffectType.RESISTANCE, Ticks.TICKS_PER_SECOND * resistanceDuration, 1);
|
||||
PotionEffect blindness = new PotionEffect(PotionEffectType.DARKNESS, Ticks.TICKS_PER_SECOND * 3, 1);
|
||||
player.addPotionEffects(List.of(resistance, blindness));
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(
|
||||
Bukkit.getScheduler().runTaskTimer(
|
||||
Main.instance(),
|
||||
() -> this.protectedPlayers.remove(player.getUniqueId()),
|
||||
Ticks.TICKS_PER_SECOND * resistanceDuration
|
||||
this::updateStatus,
|
||||
Ticks.TICKS_PER_SECOND,
|
||||
Ticks.TICKS_PER_SECOND
|
||||
);
|
||||
}
|
||||
|
||||
@@ -43,18 +46,36 @@ public class JoinProtection extends Appliance {
|
||||
return this.protectedPlayers.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
public void cancelEvent(Player player, Cancellable event) {
|
||||
var teamCountdown = Main.instance().getAppliance(Teams.class).getTeamJoinCountdown(player);
|
||||
if(teamCountdown.isFree(resistanceDuration)) return;
|
||||
event.setCancelled(true);
|
||||
public boolean isNotProtected(Player player) {
|
||||
Options options = this.protectedPlayers.get(player.getUniqueId());
|
||||
if(options == null) return true;
|
||||
return options.joinTime <= System.currentTimeMillis() - (resistanceDuration * 1000L);
|
||||
}
|
||||
|
||||
int secondsLeft = Math.abs((int) ((System.currentTimeMillis() - teamCountdown.timestampSince()) / 1000) - resistanceDuration);
|
||||
player.sendActionBar(
|
||||
Component.text(
|
||||
String.format("Du bist in %d Sekunden angreifbar", secondsLeft),
|
||||
NamedTextColor.RED
|
||||
)
|
||||
);
|
||||
public void cancelEvent(Player player, Cancellable event) {
|
||||
if(this.isNotProtected(player)) return;
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
public void updateStatus() {
|
||||
IteratorUtil.onlinePlayers(player -> {
|
||||
Options options = this.protectedPlayers.get(player.getUniqueId());
|
||||
if(options == null) return;
|
||||
|
||||
if(this.isNotProtected(player)) {
|
||||
this.protectedPlayers.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
int secondsLeft = Math.abs((int) ((System.currentTimeMillis() - options.joinTime) / 1000) - resistanceDuration);
|
||||
player.sendActionBar(
|
||||
Component.text(
|
||||
secondsLeft > 0
|
||||
? String.format("Du bist in %d Sekunden angreifbar!", secondsLeft)
|
||||
: "Du bist jetzt angreifbar!",
|
||||
NamedTextColor.RED
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.playTimer;
|
||||
|
||||
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 eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.core.config.Configuration;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks.TeamTasks;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.internal.teamTasks.tasks.CountdownTeamTask;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.Teams;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.VaroTeam;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
public class PlayTimer extends Appliance {
|
||||
public static final int PLAYTIME_MINUTES = 30;
|
||||
|
||||
private final Map<String, Integer> joinTickets = new HashMap<>();
|
||||
private final Path saveFile = Paths.get(Main.instance().getDataFolder().getAbsolutePath() + "/playtime.json");
|
||||
|
||||
public PlayTimer() {
|
||||
super("playTimer");
|
||||
this.load();
|
||||
}
|
||||
|
||||
public void changeEnabled(boolean enabled) {
|
||||
this.localConfig().set("enableTicketing", enabled);
|
||||
Configuration.saveChanges();
|
||||
}
|
||||
public boolean isEnabled() {
|
||||
return this.localConfig().getBoolean("enableTicketing", true);
|
||||
}
|
||||
|
||||
private void load() {
|
||||
if (!Files.exists(this.saveFile)) return;
|
||||
try (Reader reader = Files.newBufferedReader(this.saveFile)) {
|
||||
Type type = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
Map<String, Object> data = new Gson().fromJson(reader, type);
|
||||
@SuppressWarnings("unchecked") Map<String, Double> ticketMap = (Map<String, Double>) data.get("tickets");
|
||||
|
||||
if (ticketMap != null) {
|
||||
for (Map.Entry<String, Double> entry : ticketMap.entrySet()) {
|
||||
this.joinTickets.put(entry.getKey(), entry.getValue().intValue());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Main.logger().warning("Failed reading playtime from teams: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void save() {
|
||||
try {
|
||||
Files.createDirectories(this.saveFile.getParent());
|
||||
try (Writer writer = Files.newBufferedWriter(this.saveFile)) {
|
||||
new Gson().toJson(Map.of("tickets", this.joinTickets), writer);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Main.logger().warning("Failed to save playtime for teams: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void incrementAll() {
|
||||
Main.logger().info("Incrementing all PlayTime Tickets by one!");
|
||||
this.joinTickets.replaceAll((n, v) -> this.joinTickets.get(n) + 1);
|
||||
this.save();
|
||||
}
|
||||
public void setTickets(VaroTeam team, int amount) {
|
||||
this.joinTickets.put(team.name, amount);
|
||||
this.save();
|
||||
}
|
||||
|
||||
public int getTickets(VaroTeam team) {
|
||||
return this.joinTickets.getOrDefault(team.name, 1);
|
||||
}
|
||||
|
||||
public boolean tryConsumeTicket(VaroTeam team) {
|
||||
String teamName = team.name;
|
||||
|
||||
var teamTasks = Main.instance().getAppliance(TeamTasks.class);
|
||||
boolean isSecond = teamTasks.getRunningTeamTasks(team).containsKey(TeamTasks.Type.JOIN_PAIR);
|
||||
if(!isSecond) {
|
||||
int current = this.joinTickets.getOrDefault(teamName, 1);
|
||||
if (current <= 0) return false;
|
||||
this.joinTickets.put(teamName, current - 1);
|
||||
|
||||
var task = new CountdownTeamTask(10, announcementData -> null, component -> {}, () -> {});
|
||||
task.start();
|
||||
teamTasks.addTask(team, TeamTasks.Type.JOIN_PAIR, task);
|
||||
}
|
||||
|
||||
this.save();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void httpApi(HttpServer.ApiBuilder apiBuilder) {
|
||||
record Ticket(String team, int tickets) {}
|
||||
apiBuilder.get("tickets", request -> {
|
||||
String teamName = request.queryParamsSafe("team");
|
||||
VaroTeam team = Main.instance().getAppliance(Teams.class).findTeamByName(teamName);
|
||||
if(team == null) throw new NoSuchElementException("Team not found!");
|
||||
|
||||
return new Ticket(team.name, this.getTickets(team));
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @NotNull List<ApplianceCommand<?>> commands() {
|
||||
return List.of(
|
||||
new PlayTimerCommand(),
|
||||
new TicketingCommand()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.playTimer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.Teams;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.VaroTeam;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
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;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PlayTimerCommand extends ApplianceCommand<PlayTimer> {
|
||||
public PlayTimerCommand() {
|
||||
super("playTimer");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 3) throw new Error("Usage: playTimer <user|team> <identifier> <get|set> [amount]");
|
||||
|
||||
String mode = args[0].toLowerCase();
|
||||
String identifier = args[1];
|
||||
String action = args[2].toLowerCase();
|
||||
|
||||
Teams teamAppliance = Main.instance().getAppliance(Teams.class);
|
||||
VaroTeam team = switch (mode) {
|
||||
case "user" -> {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(identifier);
|
||||
yield teamAppliance.getTeamFromPlayer(player.getUniqueId());
|
||||
}
|
||||
case "team" -> teamAppliance.findTeamByName(identifier);
|
||||
case "incallbyone" -> {
|
||||
this.getAppliance().incrementAll();
|
||||
throw new Error("KEIN FEHLER!: Incremented all Teams by one!");
|
||||
}
|
||||
default -> throw new Error("Ungültiger Modus: " + mode + ". Erlaubt: user | team");
|
||||
};
|
||||
|
||||
if(team == null) throw new Error("Team nicht gefunden.");
|
||||
|
||||
switch (action) {
|
||||
case "get" -> {
|
||||
int ticketCount = this.getAppliance().getTickets(team);
|
||||
sender.sendMessage(String.format("Team %s hat %d tickets!", team.name, ticketCount));
|
||||
}
|
||||
case "set" -> {
|
||||
if (args.length < 4) throw new Error("Usage: playTimer <user|team> <identifier> set <amount>");
|
||||
int amount = Integer.parseInt(args[3]);
|
||||
this.getAppliance().setTickets(team, amount);
|
||||
sender.sendMessage("Tickets wurden gesetzt!");
|
||||
}
|
||||
default -> throw new Error("Ungültige Aktion: " + action + ". Erlaubt: get | set");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
List<VaroTeam> teams = Main.instance().getAppliance(Teams.class).getAllTeams();
|
||||
|
||||
return switch (args.length) {
|
||||
case 1 -> Stream.of("user", "team", "incAllByOne")
|
||||
.filter(opt -> opt.startsWith(args[0].toLowerCase()))
|
||||
.toList();
|
||||
|
||||
case 2 -> {
|
||||
if (args[0].equalsIgnoreCase("user")) {
|
||||
yield Bukkit.getOnlinePlayers().stream()
|
||||
.map(Player::getName)
|
||||
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
.toList();
|
||||
} else if (args[0].equalsIgnoreCase("team")) {
|
||||
yield teams.stream()
|
||||
.map(team -> team.name)
|
||||
.filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase()))
|
||||
.toList();
|
||||
} else {
|
||||
yield List.of();
|
||||
}
|
||||
}
|
||||
|
||||
case 3 -> Stream.of("get", "set")
|
||||
.filter(opt -> opt.startsWith(args[2].toLowerCase()))
|
||||
.toList();
|
||||
|
||||
default -> List.of();
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.playTimer;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.core.Main;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.teams.Teams;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TicketingCommand extends ApplianceCommand<PlayTimer> {
|
||||
public TicketingCommand() {
|
||||
super("ticketing");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void execute(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
sender.sendMessage(String.format("Ticketing was %b", this.getAppliance().isEnabled()));
|
||||
if(args.length < 1)
|
||||
throw new Error("Stop Ticketing with 'stop' or start ticketing (now subtracting one) and start team-countdown with 'start'");
|
||||
|
||||
switch(args[0]) {
|
||||
case "stop" -> this.getAppliance().changeEnabled(false);
|
||||
case "start" -> {
|
||||
this.getAppliance().changeEnabled(true);
|
||||
Main.instance().getAppliance(Teams.class).getAllTeams().forEach(team -> {
|
||||
boolean isAllowed = this.getAppliance().tryConsumeTicket(team);
|
||||
if(!isAllowed) {
|
||||
Main.logger().warning(String.format("Team %s already on Server, Ticketing got enabled but no Tickets were left! KICKING!", team.name));
|
||||
team.kickTeam();
|
||||
}
|
||||
|
||||
team.startCountDown();
|
||||
});
|
||||
sender.sendMessage(String.format("Ticketing (ticket reduction on join) is now %b", this.getAppliance().isEnabled()));
|
||||
}
|
||||
default -> sender.sendMessage("Unknown command");
|
||||
}
|
||||
|
||||
sender.sendMessage(String.format("Ticketing is now %b", this.getAppliance().isEnabled()));
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||
import eu.mhsl.craftattack.spawn.core.config.Configuration;
|
||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
||||
import eu.mhsl.craftattack.spawn.varo.appliances.metaGameplay.playTimer.PlayTimer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldBorder;
|
||||
@@ -35,7 +36,7 @@ public class ShrinkingBorder extends Appliance {
|
||||
@Override
|
||||
public void run() {
|
||||
Bukkit.getScheduler().runTask(Main.instance(), ShrinkingBorder.this::shrinkBorder);
|
||||
|
||||
Main.instance().getAppliance(PlayTimer.class).incrementAll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ public class ShrinkingBorderListener extends ApplianceListener<ShrinkingBorder>
|
||||
String actionBarText;
|
||||
if(remainingDays <= 0) {
|
||||
actionBarText = "Du befindest dich in der Worldborder!";
|
||||
} else if(remainingDays == 1) {
|
||||
actionBarText = "Morgen ist die Worldborder hier! Ausloggen = ☠";
|
||||
} else {
|
||||
actionBarText = String.format("In %d Tagen ist die Worldborder hier!", remainingDays);
|
||||
}
|
||||
@@ -40,8 +42,9 @@ public class ShrinkingBorderListener extends ApplianceListener<ShrinkingBorder>
|
||||
Location relativeLocation = playerLocation.clone().subtract(worldBorder.getCenter());
|
||||
double playerBorderDistanceX = worldBorder.getSize()/2 - Math.abs(relativeLocation.getX());
|
||||
double playerBorderDistanceZ = worldBorder.getSize()/2 - Math.abs(relativeLocation.getZ());
|
||||
int xSteps = (int) Math.ceil(playerBorderDistanceX / this.getAppliance().getOption(ShrinkingBorderCommand.Argument.SHRINK_PER_DAY));
|
||||
int zSteps = (int) Math.ceil(playerBorderDistanceZ / this.getAppliance().getOption(ShrinkingBorderCommand.Argument.SHRINK_PER_DAY));
|
||||
double halfShrinkPerDayX = (double) this.getAppliance().getOption(ShrinkingBorderCommand.Argument.SHRINK_PER_DAY) / 2;
|
||||
int xSteps = (int) Math.ceil(playerBorderDistanceX / halfShrinkPerDayX);
|
||||
int zSteps = (int) Math.ceil(playerBorderDistanceZ / halfShrinkPerDayX);
|
||||
return Math.min(xSteps, zSteps);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,6 @@ public class ShrinkingBorderSetting extends IntegerSetting implements Categorize
|
||||
|
||||
@Override
|
||||
protected Integer defaultValue() {
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user