mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-09-05 20:55:35 +02:00
formatting applied to most of the source code to tidy things up, and misc refactors
This commit is contained in:
@@ -2,15 +2,14 @@ package com.gmail.nossr50.util.sounds;
|
||||
|
||||
import com.gmail.nossr50.config.SoundConfig;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class SoundManager {
|
||||
private static Sound CRIPPLE_SOUND;
|
||||
|
||||
@@ -22,15 +21,18 @@ public class SoundManager {
|
||||
|
||||
/**
|
||||
* Sends a sound to the player
|
||||
*
|
||||
* @param soundType the type of sound
|
||||
*/
|
||||
public static void sendSound(Player player, Location location, SoundType soundType) {
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType))
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType)) {
|
||||
player.playSound(location, getSound(soundType),
|
||||
SoundCategory.MASTER, getVolume(soundType), getPitch(soundType));
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendCategorizedSound(Location location, SoundType soundType, SoundCategory soundCategory) {
|
||||
public static void sendCategorizedSound(Location location, SoundType soundType,
|
||||
SoundCategory soundCategory) {
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType)) {
|
||||
final World world = location.getWorld();
|
||||
if (world != null) {
|
||||
@@ -40,57 +42,69 @@ public class SoundManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendCategorizedSound(Location location, SoundType soundType, SoundCategory soundCategory,
|
||||
float pitchModifier) {
|
||||
public static void sendCategorizedSound(Location location, SoundType soundType,
|
||||
SoundCategory soundCategory,
|
||||
float pitchModifier) {
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType)) {
|
||||
final World world = location.getWorld();
|
||||
if (world != null) {
|
||||
float totalPitch = Math.min(2.0F, (getPitch(soundType) + pitchModifier));
|
||||
world.playSound(location, getSound(soundType), soundCategory, getVolume(soundType), totalPitch);
|
||||
world.playSound(location, getSound(soundType), soundCategory, getVolume(soundType),
|
||||
totalPitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendCategorizedSound(Player player, Location location,
|
||||
SoundType soundType, SoundCategory soundCategory) {
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType))
|
||||
player.playSound(location, getSound(soundType), soundCategory, getVolume(soundType), getPitch(soundType));
|
||||
SoundType soundType, SoundCategory soundCategory) {
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType)) {
|
||||
player.playSound(location, getSound(soundType), soundCategory, getVolume(soundType),
|
||||
getPitch(soundType));
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendCategorizedSound(Player player, Location location,
|
||||
SoundType soundType, SoundCategory soundCategory, float pitchModifier) {
|
||||
SoundType soundType, SoundCategory soundCategory, float pitchModifier) {
|
||||
float totalPitch = Math.min(2.0F, (getPitch(soundType) + pitchModifier));
|
||||
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType))
|
||||
player.playSound(location, getSound(soundType), soundCategory, getVolume(soundType), totalPitch);
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType)) {
|
||||
player.playSound(location, getSound(soundType), soundCategory, getVolume(soundType),
|
||||
totalPitch);
|
||||
}
|
||||
}
|
||||
|
||||
public static void worldSendSound(World world, Location location, SoundType soundType) {
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType))
|
||||
world.playSound(location, getSound(soundType), getVolume(soundType), getPitch(soundType));
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType)) {
|
||||
world.playSound(location, getSound(soundType), getVolume(soundType),
|
||||
getPitch(soundType));
|
||||
}
|
||||
}
|
||||
|
||||
public static void worldSendSoundMaxPitch(World world, Location location, SoundType soundType) {
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType))
|
||||
if (SoundConfig.getInstance().getIsEnabled(soundType)) {
|
||||
world.playSound(location, getSound(soundType), getVolume(soundType), 2.0F);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All volume is multiplied by the master volume to get its final value
|
||||
*
|
||||
* @param soundType target soundtype
|
||||
* @return the volume for this soundtype
|
||||
*/
|
||||
private static float getVolume(SoundType soundType) {
|
||||
return SoundConfig.getInstance().getVolume(soundType) * SoundConfig.getInstance().getMasterVolume();
|
||||
return SoundConfig.getInstance().getVolume(soundType) * SoundConfig.getInstance()
|
||||
.getMasterVolume();
|
||||
}
|
||||
|
||||
private static float getPitch(SoundType soundType) {
|
||||
if (soundType == SoundType.FIZZ)
|
||||
if (soundType == SoundType.FIZZ) {
|
||||
return getFizzPitch();
|
||||
else if (soundType == SoundType.POP)
|
||||
} else if (soundType == SoundType.POP) {
|
||||
return getPopPitch();
|
||||
else
|
||||
} else {
|
||||
return SoundConfig.getInstance().getPitch(soundType);
|
||||
}
|
||||
}
|
||||
|
||||
private static Sound getSound(SoundType soundType) {
|
||||
@@ -123,7 +137,8 @@ public class SoundManager {
|
||||
final Class<?> clazz = Class.forName(ORG_BUKKIT_SOUND);
|
||||
final Method valueOf = clazz.getMethod(VALUE_OF);
|
||||
CRIPPLE_SOUND = (Sound) valueOf.invoke(null, ITEM_MACE_SMASH_GROUND);
|
||||
} catch (IllegalArgumentException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException
|
||||
} catch (IllegalArgumentException | ClassNotFoundException | NoSuchMethodException |
|
||||
InvocationTargetException
|
||||
| IllegalAccessException e) {
|
||||
CRIPPLE_SOUND = Sound.BLOCK_ANVIL_PLACE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user