Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
YouHaveTrouble committed Jun 26, 2024
2 parents bf67b28 + b99e5f4 commit 66b0208
Showing 1 changed file with 48 additions and 0 deletions.
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);
}
}

0 comments on commit 66b0208

Please sign in to comment.