-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/main/java/org/purpurmc/purpurextras/modules/LeashSnapSoundModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.purpurmc.purpurextras.modules; | ||
|
||
import net.kyori.adventure.key.Key; | ||
import net.kyori.adventure.sound.Sound; | ||
import org.bukkit.NamespacedKey; | ||
import org.bukkit.SoundCategory; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.entity.EntityUnleashEvent; | ||
import org.purpurmc.purpurextras.PurpurExtras; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* Adds a sound for when the leash snaps | ||
*/ | ||
public class LeashSnapSoundModule implements PurpurExtrasModule, Listener { | ||
|
||
private String sound; | ||
private double volume; | ||
private double pitch; | ||
|
||
protected LeashSnapSoundModule() { | ||
sound = PurpurExtras.getPurpurConfig().getString("settings.leash-snap.sound", "minecraft:block.bamboo.break"); | ||
volume = PurpurExtras.getPurpurConfig().getDouble("settings.leash-snap.volume", 1f); | ||
pitch = PurpurExtras.getPurpurConfig().getDouble("settings.leash-snap.pitch", 1.25f); | ||
} | ||
|
||
@Override | ||
public void enable() { | ||
PurpurExtras plugin = PurpurExtras.getInstance(); | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
@Override | ||
public boolean shouldEnable() { | ||
return PurpurExtras.getPurpurConfig().getBoolean("settings.leash-snap.enabled", false) && sound != null; | ||
} | ||
|
||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) | ||
public void onLeashBreak(EntityUnleashEvent event){ | ||
|
||
if (event.getReason() != EntityUnleashEvent.UnleashReason.DISTANCE) return; | ||
|
||
event.getEntity().getWorld().playSound(event.getEntity().getLocation(), sound, SoundCategory.PLAYERS, (float) volume, (float) pitch); | ||
} | ||
} |