Skip to content

Commit

Permalink
NMS backing for player.stop_sound mech
Browse files Browse the repository at this point in the history
since spigot went and broked it
  • Loading branch information
mcmonkey4eva committed May 17, 2020
1 parent 0e0100f commit 560ab4d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
Expand Up @@ -2,10 +2,7 @@

import com.denizenscript.denizen.nms.abstracts.ImprovedOfflinePlayer;
import com.denizenscript.denizencore.objects.Mechanism;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.*;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
Expand All @@ -14,6 +11,8 @@

public abstract class PlayerHelper {

public abstract void stopSound(Player player, String sound, SoundCategory category);

public Entity sendEntitySpawn(Player player, EntityType entityType, Location location, ArrayList<Mechanism> mechanisms) {
throw new UnsupportedOperationException();
}
Expand Down
Expand Up @@ -3563,17 +3563,16 @@ else if (split.length > 1) {
// If no sound type is specified, all types will be stopped.
// -->
if (mechanism.matches("stop_sound")) {
if (!mechanism.hasValue()) {
getPlayerEntity().stopSound("");
}
else {
SoundCategory category = SoundCategory.MASTER;
if (mechanism.hasValue()) {
try {
getPlayerEntity().stopSound("", SoundCategory.valueOf(mechanism.getValue().asString().toUpperCase()));
category = SoundCategory.valueOf(mechanism.getValue().asString().toUpperCase());
}
catch (Exception e) {
Debug.echoError("Invalid SoundCategory. Must specify a valid name.");
}
}
NMSHandler.getPlayerHelper().stopSound(getPlayerEntity(), null, category);
}

if (mechanism.matches("action_bar")) {
Expand Down
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.Chunk;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.SoundCategory;
import org.bukkit.craftbukkit.v1_12_R1.CraftServer;
import org.bukkit.craftbukkit.v1_12_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
Expand Down Expand Up @@ -45,6 +46,11 @@ public int getFlyKickCooldown(Player player) {
return 80;
}

@Override
public void stopSound(Player player, String sound, SoundCategory category) {
player.stopSound(sound == null ? "" : sound, category);
}

@Override
public void setFlyKickCooldown(Player player, int ticks) {
ticks = 80 - ticks;
Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.Chunk;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.SoundCategory;
import org.bukkit.craftbukkit.v1_13_R2.CraftServer;
import org.bukkit.craftbukkit.v1_13_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer;
Expand Down Expand Up @@ -44,6 +45,12 @@ public class PlayerHelperImpl extends PlayerHelper {
ENTITY_HUMAN_SKINLAYERS_DATAWATCHER = skinlayers;
}

@Override
public void stopSound(Player player, String sound, SoundCategory category) {
MinecraftKey soundKey = sound == null ? null : new MinecraftKey(sound);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutStopSound(soundKey, net.minecraft.server.v1_13_R2.SoundCategory.valueOf(category.name())));
}

@Override
public int getFlyKickCooldown(Player player) {
PlayerConnection conn = ((CraftPlayer) player).getHandle().playerConnection;
Expand Down
Expand Up @@ -13,6 +13,7 @@
import org.bukkit.Chunk;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.SoundCategory;
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
Expand Down Expand Up @@ -44,6 +45,12 @@ public class PlayerHelperImpl extends PlayerHelper {
ENTITY_HUMAN_SKINLAYERS_DATAWATCHER = skinlayers;
}

@Override
public void stopSound(Player player, String sound, SoundCategory category) {
MinecraftKey soundKey = sound == null ? null : new MinecraftKey(sound);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutStopSound(soundKey, net.minecraft.server.v1_14_R1.SoundCategory.valueOf(category.name())));
}

@Override
public int getFlyKickCooldown(Player player) {
PlayerConnection conn = ((CraftPlayer) player).getHandle().playerConnection;
Expand Down
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.server.v1_15_R1.*;
import org.bukkit.*;
import org.bukkit.Chunk;
import org.bukkit.SoundCategory;
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
Expand Down Expand Up @@ -47,6 +48,12 @@ public class PlayerHelperImpl extends PlayerHelper {
ENTITY_HUMAN_SKINLAYERS_DATAWATCHER = skinlayers;
}

@Override
public void stopSound(Player player, String sound, SoundCategory category) {
MinecraftKey soundKey = sound == null ? null : new MinecraftKey(sound);
((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutStopSound(soundKey, net.minecraft.server.v1_15_R1.SoundCategory.valueOf(category.name())));
}

@Override
public Entity sendEntitySpawn(Player player, EntityType entityType, Location location, ArrayList<Mechanism> mechanisms) {
PlayerConnection conn = ((CraftPlayer) player).getHandle().playerConnection;
Expand Down

0 comments on commit 560ab4d

Please sign in to comment.