From df347fde7f07ce3e0c8d743cd0a6fa4e5ab3e4c2 Mon Sep 17 00:00:00 2001 From: akastijn Date: Fri, 31 Oct 2025 01:45:54 +0100 Subject: [PATCH] Add PlayerJoin event listener to modify player attributes on join and update project configuration --- build.gradle.kts | 2 +- settings.gradle.kts | 16 ++++++-- .../com/alttd/playerutils/PlayerUtils.java | 1 + .../com/alttd/playerutils/config/Config.java | 13 +++++++ .../event_listeners/PlayerJoin.java | 38 +++++++++++++++++++ 5 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/alttd/playerutils/event_listeners/PlayerJoin.java diff --git a/build.gradle.kts b/build.gradle.kts index efa46bd..b59db9b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,7 +39,7 @@ tasks { } dependencies { - compileOnly("com.alttd.cosmos:cosmos-api:1.21.7-R0.1-SNAPSHOT") { + compileOnly("com.alttd.cosmos:cosmos-api:1.21.10-R0.1-SNAPSHOT") { isChanging = true } diff --git a/settings.gradle.kts b/settings.gradle.kts index cd52506..7700186 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,11 +1,21 @@ -rootProject.name = "PlayerUtils" +rootProject.name = "StaffUtils" + +val nexusUser = providers.gradleProperty("alttdSnapshotUsername").orNull ?: System.getenv("NEXUS_USERNAME") +val nexusPass = providers.gradleProperty("alttdSnapshotPassword").orNull ?: System.getenv("NEXUS_PASSWORD") dependencyResolutionManagement { repositories { mavenLocal() mavenCentral() - maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy - maven("'https://jitpack.io'") // Vault + maven { + url = uri("https://repo.alttd.com/repository/alttd-snapshot/") + credentials { + username = nexusUser + password = nexusPass + } + } + maven("https://repo.destro.xyz/snapshots") + maven("https://jitpack.io") } repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) } diff --git a/src/main/java/com/alttd/playerutils/PlayerUtils.java b/src/main/java/com/alttd/playerutils/PlayerUtils.java index 9538db0..7f596f2 100644 --- a/src/main/java/com/alttd/playerutils/PlayerUtils.java +++ b/src/main/java/com/alttd/playerutils/PlayerUtils.java @@ -41,6 +41,7 @@ public final class PlayerUtils extends JavaPlugin { pluginManager.registerEvents(new GoatHornEvent(), this); pluginManager.registerEvents(new LimitArmorStands(this), this); pluginManager.registerEvents(new BlockBlockUseEvent(), this); + pluginManager.registerEvents(new PlayerJoin(), this); RotateBlockEvent rotateBlockEvent = new RotateBlockEvent(); pluginManager.registerEvents(rotateBlockEvent, this); diff --git a/src/main/java/com/alttd/playerutils/config/Config.java b/src/main/java/com/alttd/playerutils/config/Config.java index 8d52089..05db98f 100644 --- a/src/main/java/com/alttd/playerutils/config/Config.java +++ b/src/main/java/com/alttd/playerutils/config/Config.java @@ -79,4 +79,17 @@ import java.util.Set; } } } + + public static class LOCATOR_BAR { + private static final String prefix = "locator_bar."; + + public static double WAYPOINT_RECEIVE_RANGE = 200; + public static double WAYPOINT_TRANSMIT_RANGE = 200; + + @SuppressWarnings("unused") + private static void load() { + WAYPOINT_RECEIVE_RANGE = config.getDouble(prefix, "waypoint_receive_range", WAYPOINT_RECEIVE_RANGE); + WAYPOINT_TRANSMIT_RANGE = config.getDouble(prefix, "waypoint_transmit_range", WAYPOINT_TRANSMIT_RANGE); + } + } } diff --git a/src/main/java/com/alttd/playerutils/event_listeners/PlayerJoin.java b/src/main/java/com/alttd/playerutils/event_listeners/PlayerJoin.java new file mode 100644 index 0000000..c88bbb7 --- /dev/null +++ b/src/main/java/com/alttd/playerutils/event_listeners/PlayerJoin.java @@ -0,0 +1,38 @@ +package com.alttd.playerutils.event_listeners; + +import com.alttd.playerutils.config.Config; +import lombok.extern.slf4j.Slf4j; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeInstance; +import org.bukkit.attribute.AttributeModifier; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +@Slf4j +public class PlayerJoin implements Listener { + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + setModifiedAttribute(player, Attribute.WAYPOINT_RECEIVE_RANGE, Config.LOCATOR_BAR.WAYPOINT_RECEIVE_RANGE); + setModifiedAttribute(player, Attribute.WAYPOINT_TRANSMIT_RANGE, Config.LOCATOR_BAR.WAYPOINT_TRANSMIT_RANGE); + } + + private void setModifiedAttribute(Player player, Attribute attribute, double configValue) { + AttributeInstance attributeInstance = player.getAttribute(attribute); + + if (attributeInstance == null) { + log.error("Unable to retrieve attribute instance for player {}.", player.getName()); + return; + } + + double waypointReceiveDelta = attributeInstance.getValue() - configValue; + AttributeModifier attributeModifier = new AttributeModifier(attribute.getKey(), + waypointReceiveDelta, + AttributeModifier.Operation.ADD_NUMBER); + attributeInstance.addModifier(attributeModifier); + } + +}