Properly send Halloween sounds in 1.12 and up

This commit is contained in:
Dan Mulloy 2017-10-07 15:39:14 -04:00
parent 285ca1e707
commit 278f17b34d

View File

@ -6,12 +6,15 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import com.mineplex.ProtocolVersion;
import org.bukkit.ChatColor;
import org.bukkit.Difficulty;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -58,6 +61,9 @@ import nautilus.game.arcade.game.games.halloween.waves.WaveVictory;
import nautilus.game.arcade.game.modules.compass.CompassModule;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.managers.chat.ChatStatData;
import net.minecraft.server.v1_8_R3.Packet;
import net.minecraft.server.v1_8_R3.PacketPlayOutCustomSoundEffect;
import net.minecraft.server.v1_8_R3.PacketPlayOutNamedSoundEffect;
public class Halloween extends SoloGame
@ -641,20 +647,35 @@ public class Halloween extends SoloGame
}
}
// Custom handling to make sure 1.12+ actually hear the sound
public void playSound(NamedAudio audio)
{
for (Player player : UtilServer.getPlayers())
{
if (!_soundOff.contains(player))
{
PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(audio.getAudioPath(),
player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ(),
20f, 1F);
{
Packet packet;
int protocol = ((CraftPlayer) player).getHandle().getProtocol();
if (protocol >= ProtocolVersion.v1_12)
{
packet = new PacketPlayOutCustomSoundEffect(audio.getAudioPath(),
player.getLocation().getX(), player.getLocation().getY(),
player.getLocation().getZ(), 20f, 1f);
} else
{
packet = new PacketPlayOutNamedSoundEffect(audio.getAudioPath(),
player.getLocation().getBlockX(), player.getLocation().getBlockY(),
player.getLocation().getBlockZ(),
20f, 1f);
}
UtilPlayer.sendPacket(player, packet);
}
}
}
private int hungerTick = 0;
@EventHandler
public void Hunger(UpdateEvent event)
{