Skip to content

Commit

Permalink
v2.1.2 version release.
Browse files Browse the repository at this point in the history
Added play sound nearby feature by #25.
  • Loading branch information
imDMK committed Feb 23, 2024
1 parent 2174382 commit fc6e1ac
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 6 deletions.
2 changes: 1 addition & 1 deletion doublejump-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "com.github.imdmk"
version = "2.1.0"
version = "2.1.2"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion doublejump-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "com.github.imdmk"
version = "2.1.1"
version = "2.1.2"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.github.imdmk.doublejump.jump.placeholder.jumps.JumpPlayerJumpsLimitPlaceholder;
import com.github.imdmk.doublejump.jump.placeholder.jumps.JumpPlayerJumpsPlaceholder;
import com.github.imdmk.doublejump.jump.restriction.JumpRestrictionService;
import com.github.imdmk.doublejump.jump.sound.JumpSoundService;
import com.github.imdmk.doublejump.notification.Notification;
import com.github.imdmk.doublejump.notification.NotificationSender;
import com.github.imdmk.doublejump.placeholder.PlaceholderRegistry;
Expand Down Expand Up @@ -114,6 +115,7 @@ public DoubleJump(Plugin plugin) {
this.jumpRestrictionService = new JumpRestrictionService(this.pluginConfiguration.jumpSettings, this.pluginConfiguration.jumpSettings.restrictionSettings, this.regionProvider, this.notificationSender);

JumpItemService jumpItemService = new JumpItemService(this.pluginConfiguration.jumpSettings.itemSettings);
JumpSoundService jumpSoundService = new JumpSoundService(this.pluginConfiguration);
UpdateService updateService = new UpdateService(pluginDescriptionFile);

/* Task Scheduler */
Expand All @@ -126,7 +128,7 @@ public DoubleJump(Plugin plugin) {
new JumpItemDropListener(this.pluginConfiguration.jumpSettings.itemSettings, jumpItemService, this.jumpPlayerService),
new JumpItemEnableListener(this.pluginConfiguration.jumpSettings.itemSettings, this.jumpPlayerManager, this.jumpPlayerService, jumpItemService),
new JumpItemInteractListener(this.server, this.pluginConfiguration.jumpSettings, this.pluginConfiguration.jumpSettings.itemSettings, this.notificationSender, this.jumpPlayerManager, this.jumpPlayerService, jumpItemService, this.jumpRestrictionService),
new DoubleJumpListener(this.pluginConfiguration.jumpSettings, this.notificationSender),
new DoubleJumpListener(this.pluginConfiguration.jumpSettings, jumpSoundService, this.notificationSender),
new JumpDisableListener(this.jumpPlayerManager, this.jumpPlayerService, this.jumpRestrictionService, taskScheduler),
new JumpEnableListener(this.server, this.pluginConfiguration.jumpSettings, this.jumpPlayerManager, this.jumpPlayerService, this.jumpRestrictionService, taskScheduler),
new JumpFallDamageListener(this.pluginConfiguration.jumpSettings, this.jumpPlayerManager),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.imdmk.doublejump.jump.JumpPlayer;
import com.github.imdmk.doublejump.jump.JumpSettings;
import com.github.imdmk.doublejump.jump.event.DoubleJumpEvent;
import com.github.imdmk.doublejump.jump.sound.JumpSoundService;
import com.github.imdmk.doublejump.notification.NotificationSender;
import com.github.imdmk.doublejump.text.Formatter;
import org.bukkit.Location;
Expand All @@ -15,10 +16,12 @@
public class DoubleJumpListener implements Listener {

private final JumpSettings jumpSettings;
private final JumpSoundService jumpSoundService;
private final NotificationSender notificationSender;

public DoubleJumpListener(JumpSettings jumpSettings, NotificationSender notificationSender) {
public DoubleJumpListener(JumpSettings jumpSettings, JumpSoundService jumpSoundService, NotificationSender notificationSender) {
this.jumpSettings = jumpSettings;
this.jumpSoundService = jumpSoundService;
this.notificationSender = notificationSender;
}

Expand Down Expand Up @@ -46,8 +49,12 @@ public void onDoubleJump(DoubleJumpEvent event) {
jumpPlayer.addDelay(this.jumpSettings.delaySettings.delay);
}

if (this.jumpSettings.soundSettings.enabled) {
this.jumpSettings.soundSettings.sounds.forEach(sound -> sound.play(player));
if (this.jumpSoundService.isSoundsEnabled()) {
this.jumpSoundService.play(player);

if (this.jumpSoundService.isPlayNearbyEnabled()) {
this.jumpSoundService.playNearby(player);
}
}

if (this.jumpSettings.particleSettings.enabled) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.imdmk.doublejump.jump.sound;

import com.github.imdmk.doublejump.configuration.implementation.PluginConfiguration;
import com.github.imdmk.doublejump.jump.JumpSettings;
import com.github.imdmk.doublejump.placeholder.PlaceholderRegistry;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

import java.util.List;

public class JumpSoundService {

private final JumpSoundSettings jumpSoundSettings;

public JumpSoundService(PluginConfiguration pluginConfiguration) {
this.jumpSoundSettings = pluginConfiguration.jumpSettings.soundSettings;
}

public void play(Player player) {
this.jumpSoundSettings.sounds.forEach(sound -> sound.play(player));
}

public void playNearby(Player player) {
double nearbyX = this.jumpSoundSettings.playNearbyX;
double nearbyY = this.jumpSoundSettings.playNearbyY;
double nearbyZ = this.jumpSoundSettings.playNearbyZ;

List<Entity> nearbyEntities = player.getNearbyEntities(nearbyX, nearbyY, nearbyZ);

for (Entity entity : nearbyEntities) {
if (!(entity instanceof Player other)) {
return;
}

this.play(other);
}
}

public boolean isSoundsEnabled() {
return this.jumpSoundSettings.enabled;
}

public boolean isPlayNearbyEnabled() {
return this.jumpSoundSettings.playNearbyEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ public class JumpSoundSettings extends OkaeriConfig {
@Comment("# Specifies whether to enable double jump sound")
public boolean enabled = true;

@Comment("# Specifies whether nearby players should hear the jump sound")
public boolean playNearbyEnabled = true;

@Comment("# Specifies the distance in X coordinates at which the jump sound should be played")
public double playNearbyX = 5;

@Comment("# Specifies the distance in Y coordinates at which the jump sound should be played")
public double playNearbyY = 5;

@Comment("# Specifies the distance in Z coordinates at which the jump sound should be played")
public double playNearbyZ = 5;

@Comment("# List of available sounds: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Sound.html")
public List<JumpSound> sounds = List.of(
new JumpSound(Sound.ENTITY_EXPERIENCE_BOTTLE_THROW, 0.20F, 1),
Expand Down

0 comments on commit fc6e1ac

Please sign in to comment.