mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-11-14 10:45:23 +01:00
Add open/close sound effects
This commit is contained in:
parent
01776e3489
commit
56d4280e38
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>at.pcgamingfreaks</groupId>
|
||||
<artifactId>Minepacks</artifactId>
|
||||
<version>2.1-RC1</version>
|
||||
<version>2.1-RC2</version>
|
||||
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:GeorgH93/Minepacks.git</connection>
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<GameMode> 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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user