diff --git a/pom.xml b/pom.xml index 4ab097c..89b9b01 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 at.pcgamingfreaks Minepacks - 2.1-RC1 + 2.1-RC2 scm:git:git@github.com:GeorgH93/Minepacks.git diff --git a/resources/config.yml b/resources/config.yml index 3cd674d..7cdb6ff 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -158,6 +158,18 @@ ItemShortcut: # The correct value is the one listed on the head page under Other/Value HeadTextureValue: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGRjYzZlYjQwZjNiYWRhNDFlNDMzOTg4OGQ2ZDIwNzQzNzU5OGJkYmQxNzVjMmU3MzExOTFkNWE5YTQyZDNjOCJ9fX0=" +Sound: + # Enables all sound effects + Enabled: true + # The sound effect that should be played if the backpack is opened + # disabled or false to disable the sound effect + # auto will play the chest sound for minecraft versions older than 1.11 and the shulker-box sound for newer MC versions + OpenSound: auto + # The sound effect that should be played if the backpack is closed + # disabled or false to disable the sound effect + # auto will play the chest sound for minecraft versions older than 1.11 and the shulker-box sound for newer MC versions + CloseSound: auto + Misc: # Enables/Disables the auto-update function of the plugin. AutoUpdate: true diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java index 1d2ea05..9c05060 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Database/Config.java @@ -28,6 +28,7 @@ import org.bukkit.ChatColor; import org.bukkit.GameMode; +import org.bukkit.Sound; import org.bukkit.plugin.java.JavaPlugin; import org.jetbrains.annotations.NotNull; @@ -329,5 +330,34 @@ public String getItemShortcutHeadValue() return getConfigE().getString("ItemShortcut.HeadTextureValue", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGRjYzZlYjQwZjNiYWRhNDFlNDMzOTg4OGQ2ZDIwNzQzNzU5OGJkYmQxNzVjMmU3MzExOTFkNWE5YTQyZDNjOCJ9fX0="); } //endregion + + //region Sound settings + private Sound getSound(String option, Sound autoValue) + { + if(!getConfigE().getBoolean("Sound.Enabled", true)) return null; + String soundName = getConfigE().getString("Sound." + option, "auto").toUpperCase(Locale.ENGLISH); + if(soundName.equals("AUTO")) return autoValue; + if(soundName.equals("DISABLED") || soundName.equals("FALSE")) return null; + try + { + return Sound.valueOf(soundName); + } + catch(Exception ignored) + { + logger.warning("Unknown sound: " + soundName); + } + return null; + } + + public Sound getOpenSound() + { + return getSound("OpenSound", MCVersion.isNewerOrEqualThan(MCVersion.MC_1_11) ? Sound.valueOf("BLOCK_SHULKER_BOX_OPEN") : (MCVersion.isNewerOrEqualThan(MCVersion.MC_1_9_2) ? Sound.BLOCK_CHEST_OPEN : Sound.valueOf("CHEST_OPEN"))); + } + + public Sound getCloseSound() + { + return getSound("CloseSound", MCVersion.isNewerOrEqualThan(MCVersion.MC_1_11) ? Sound.valueOf("BLOCK_SHULKER_BOX_CLOSE") : (MCVersion.isNewerOrEqualThan(MCVersion.MC_1_9_2) ? Sound.BLOCK_CHEST_CLOSE : Sound.valueOf("CHEST_CLOSE"))); + } + //endregion //endregion } \ No newline at end of file diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/BackpackEventListener.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/BackpackEventListener.java index 12b303e..26cbe7a 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/BackpackEventListener.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Listener/BackpackEventListener.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016-2018 GeorgH93 + * Copyright (C) 2020 GeorgH93 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +23,7 @@ import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; +import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -33,12 +34,14 @@ public class BackpackEventListener extends MinepacksListener { private final Message messageOwnBackpackClose, messageOtherBackpackClose; + private final Sound closeSound; public BackpackEventListener(Minepacks plugin) { super(plugin); messageOwnBackpackClose = plugin.getLanguage().getMessage("Ingame.OwnBackpackClose"); messageOtherBackpackClose = plugin.getLanguage().getMessage("Ingame.PlayerBackpackClose").replaceAll("\\{OwnerName\\}", "%1\\$s").replaceAll("\\{OwnerDisplayName\\}", "%2\\$s"); + closeSound = plugin.getConfiguration().getCloseSound(); } @EventHandler @@ -62,6 +65,10 @@ public void onClose(InventoryCloseEvent event) OfflinePlayer owner = backpack.getOwner(); messageOtherBackpackClose.send(closer, owner.getName(), owner.isOnline() ? owner.getPlayer().getDisplayName() : ChatColor.GRAY + owner.getName()); } + if(closeSound != null) + { + closer.getWorld().playSound(closer.getLocation(), closeSound, 1, 0); + } } } diff --git a/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java b/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java index fcc1993..a5ea731 100644 --- a/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java +++ b/src/at/pcgamingfreaks/Minepacks/Bukkit/Minepacks.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 GeorgH93 + * Copyright (C) 2020 GeorgH93 * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,6 +41,7 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.OfflinePlayer; +import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.plugin.PluginManager; @@ -73,6 +74,7 @@ public class Minepacks extends JavaPlugin implements MinepacksPlugin private Collection gameModes; private CooldownManager cooldownManager = null; private ItemFilter itemFilter = null; + private Sound openSound = null; public static Minepacks getInstance() { @@ -200,6 +202,8 @@ private void load() gameModes = config.getAllowedGameModes(); if(config.getCommandCooldown() > 0) cooldownManager = new CooldownManager(this); + + openSound = config.getOpenSound(); } private void unload() @@ -294,6 +298,10 @@ public void openBackpack(@NotNull Player opener, @Nullable Backpack backpack, bo messageInvalidBackpack.send(opener); return; } + if(openSound != null) + { + opener.getWorld().playSound(opener.getLocation(), openSound, 1, 0); + } backpack.open(opener, editable); }