Skip to content

Commit

Permalink
Merge pull request #60 from CallVDois/volume-option
Browse files Browse the repository at this point in the history
Volume option
  • Loading branch information
needkg authored Jul 17, 2024
2 parents 20378cc + e023183 commit 7a31748
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>org.callv2</groupId>
<artifactId>DayNightPvP</artifactId>
<name>DayNightPvP</name>
<version>1.2.6.2</version>
<version>1.2.6.3</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
46 changes: 39 additions & 7 deletions src/main/java/org/callv2/daynightpvp/files/ConfigFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public void createFile() {
}

private void verifyFileVersion() {
int lastestFileVersion = 16;
if (lastestFileVersion != getVersion()) {
int latestFileVersion = 17;
if (latestFileVersion != getVersion()) {
resetFile();
String fileOutdated = "[DayNightPvP] The \"config.yml\" file was an outdated version. it has been replaced by the new version.";
ConsoleUtils.sendWarningMessage(fileOutdated);
Expand Down Expand Up @@ -61,7 +61,7 @@ private void resetValueToDefault(String path, Object value) {
ConsoleUtils.sendWarningMessage("[DayNightPvP] The \"" + configName + "\" configuration was set incorrectly and has been reset.");
}

private int getInt(String path, Integer defaultValue, int minValue, int maxValue) {
private int getInt(String path, Integer defaultValue, Integer minValue, Integer maxValue) {

String configValue = fileContent.getString(path);

Expand All @@ -85,6 +85,30 @@ private int getInt(String path, Integer defaultValue, int minValue, int maxValue
}
}

private float getFloat(String path, Float defaultValue, Float minValue, Float maxValue) {

String configValue = fileContent.getString(path);

if (configValue == null) {
resetFile();
return defaultValue;
}

try {
float floatValue = Float.parseFloat(configValue);

if (floatValue >= minValue && floatValue <= maxValue) {
return floatValue;
} else {
resetValueToDefault(path, defaultValue);
return defaultValue;
}
} catch (Exception e) {
resetValueToDefault(path, defaultValue);
return defaultValue;
}
}

private Difficulty getDifficulty(String path, Difficulty defaultValue) {

String configValue = fileContent.getString(path);
Expand Down Expand Up @@ -255,12 +279,20 @@ public boolean getNotifyPlayersSoundEnabled() {
return getBoolean("notify-players.sound.enabled", true);
}

public Sound getNotifyPlayersSoundDay() {
return getSound("notify-players.sound.day", Sound.ENTITY_CHICKEN_AMBIENT);
public Sound getNotifyPlayersSoundDaySound() {
return getSound("notify-players.sound.day.sound", Sound.ENTITY_CHICKEN_AMBIENT);
}

public float getNotifyPlayersSoundDayVolume() {
return getFloat("notify-players.sound.day.volume", 1.0f, 0.0f, 1.0f);
}

public float getNotifyPlayersSoundNightVolume() {
return getFloat("notify-players.sound.night.volume", 1.0f, 0.0f, 1.0f);
}

public Sound getNotifyPlayersSoundNight() {
return getSound("notify-players.sound.night", Sound.ENTITY_GHAST_AMBIENT);
public Sound getNotifyPlayersSoundNightSound() {
return getSound("notify-players.sound.night.sound", Sound.ENTITY_GHAST_AMBIENT);
}

public boolean getPvpKeepInventoryWhenKilledByPlayer() {
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/org/callv2/daynightpvp/runnables/AutomaticPvp.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class AutomaticPvp extends BukkitRunnable {
private final int fadeIn;
private final int stay;
private final int fadeOut;
private final float soundNightVolume;
private final float soundDayVolume;

public AutomaticPvp(ConfigFile configFile, LangFile langFile) {
this.dayEnd = configFile.getDayNightPvpDayEnd();
Expand All @@ -50,12 +52,14 @@ public AutomaticPvp(ConfigFile configFile, LangFile langFile) {
this.notifyNightChat = langFile.getNotifyNightChat();
this.notifyNightTitle = langFile.getNotifyNightTitle();
this.notifyNightSubtitle = langFile.getNotifyNightSubtitle();
this.notifyPlayersSoundDay = configFile.getNotifyPlayersSoundDay();
this.notifyPlayersSoundNight = configFile.getNotifyPlayersSoundNight();
this.notifyPlayersSoundDay = configFile.getNotifyPlayersSoundDaySound();
this.notifyPlayersSoundNight = configFile.getNotifyPlayersSoundNightSound();
this.worldList = configFile.getDayNightPvpWorlds();
this.fadeIn = configFile.getNotifyPlayersTitleFadeIn();
this.stay = configFile.getNotifyPlayersTitleStay();
this.fadeOut = configFile.getNotifyPlayersTitleFadeOut();
this.soundNightVolume = configFile.getNotifyPlayersSoundNightVolume();
this.soundDayVolume = configFile.getNotifyPlayersSoundDayVolume();
}

@Override
Expand Down Expand Up @@ -126,7 +130,8 @@ private void notifyPlayers(World world, boolean isNight) {
}
if (notifyPlayersSoundEnabled) {
PlayerUtils.playSoundToAllPlayers(world,
isNight ? notifyPlayersSoundNight : notifyPlayersSoundDay);
isNight ? notifyPlayersSoundNight : notifyPlayersSoundDay,
isNight ? soundNightVolume : soundDayVolume);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/callv2/daynightpvp/utils/PlayerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public static void sendMessageToAllPlayers(World world, String message) {
}
}

public static void playSoundToAllPlayers(World world, Sound sound) {
public static void playSoundToAllPlayers(World world, Sound sound, Float volume) {
for (Player player : world.getPlayers()) {
player.playSound(player.getLocation(), sound, 1, 1);
player.playSound(player.getLocation(), sound, volume, 1);
}
}

Expand Down
22 changes: 17 additions & 5 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is the version of the file, DO NOT MODIFY.
version: 16
version: 17

# Enables or disables the update checker (recommended to use as true).
# Setting type: Boolean
Expand Down Expand Up @@ -84,10 +84,22 @@ notify-players:
fade-out: 20
sound:
enabled: true
# Setting type: String
# Acceptable values: https://github.com/CallVDois/DayNightPvP/wiki/Sounds
day: ENTITY_CHICKEN_AMBIENT
night: ENTITY_GHAST_AMBIENT
day:
# Setting type: String
# Acceptable values: https://github.com/CallVDois/DayNightPvP/wiki/Sounds
sound: ENTITY_CHICKEN_AMBIENT
# Setting type: Float
# Default value: 1.0
# Setting range: 0.0 - 1.0
volume: 1.0
night:
# Setting type: String
# Acceptable values: https://github.com/CallVDois/DayNightPvP/wiki/Sounds
sound: ENTITY_GHAST_AMBIENT
# Setting type: Float
# Default value: 1.0
# Setting range: 0.0 - 1.0
volume: 1.0

pvp:
# If set to true, the killed player should not lose items when killed by another player.
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ feedback-update-available: "&9&lDayNightPvP &8-> &7Update available!"
feedback-update-current-version: "&7Current version: &c{0}"
feedback-update-latest-version: "&7Latest version: &b{0}"
feedback-update-check-failed: "&9&lDayNightPvP &8-> &7Failed to check for updates."
feedback-reload-plugin: "&a&lSuccess! &7Configuration files reloaded!"
feedback-reload-plugin: "&a&lSuccess! &7Plugin reloaded!"
feedback-lose-money: "&e&lWarning! &7You died to &b{0} &7and lost &c${1}"
feedback-win-money: "&e&lWarning! &7You killed &b{0} &7and earned &a${1}"
feedback-non-existent-command: "&c&lError! &7This command does not exist!"
Expand Down

0 comments on commit 7a31748

Please sign in to comment.