From b92ea876e083084ef23be612598ccd3797621ff7 Mon Sep 17 00:00:00 2001 From: PseudoKnight Date: Mon, 1 Apr 2024 20:22:53 -0700 Subject: [PATCH] Add stop_sound_category() --- .../com/laytonsmith/abstraction/MCPlayer.java | 2 + .../bukkit/entities/BukkitMCPlayer.java | 9 +++ .../core/functions/PlayerManagement.java | 55 +++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/src/main/java/com/laytonsmith/abstraction/MCPlayer.java b/src/main/java/com/laytonsmith/abstraction/MCPlayer.java index 16304c087..55c0e2d7e 100644 --- a/src/main/java/com/laytonsmith/abstraction/MCPlayer.java +++ b/src/main/java/com/laytonsmith/abstraction/MCPlayer.java @@ -161,6 +161,8 @@ public interface MCPlayer extends MCCommandSender, MCHumanEntity, MCOfflinePlaye void stopSound(String sound, MCSoundCategory category); + void stopSound(MCSoundCategory category); + void spawnParticle(MCLocation l, MCParticle pa, int count, double offsetX, double offsetY, double offsetZ, double velocity, Object data); int getFoodLevel(); diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java index 7d4673d13..79afa457d 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java @@ -647,6 +647,15 @@ public void stopSound(String sound, MCSoundCategory category) { p.stopSound(sound, BukkitMCSoundCategory.getConvertor().getConcreteEnum(category)); } + @Override + public void stopSound(MCSoundCategory category) { + try { + p.stopSound(BukkitMCSoundCategory.getConvertor().getConcreteEnum(category)); + } catch (NoSuchMethodError ex) { + // probably before 1.19.0 + } + } + @Override public void spawnParticle(MCLocation l, MCParticle pa, int count, double offsetX, double offsetY, double offsetZ, double velocity, Object data) { p.spawnParticle((Particle) pa.getConcrete(), (Location) l.getHandle(), count, offsetX, offsetY, offsetZ, diff --git a/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java b/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java index 68d3ea9d7..7adf43246 100644 --- a/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java +++ b/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java @@ -5608,6 +5608,61 @@ public MSVersion since() { } + @api(environments = {CommandHelperEnvironment.class}) + @seealso({com.laytonsmith.core.functions.Environment.play_sound.class}) + public static class stop_sound_category extends AbstractFunction { + + @Override + public Class[] thrown() { + return new Class[]{CRELengthException.class, CREFormatException.class, CREPlayerOfflineException.class}; + } + + @Override + public boolean isRestricted() { + return true; + } + + @Override + public Boolean runAsync() { + return false; + } + + @Override + public Mixed exec(Target t, com.laytonsmith.core.environments.Environment environment, Mixed... args) + throws ConfigRuntimeException { + + MCPlayer p = Static.GetPlayer(args[0], t); + MCSoundCategory category; + try { + category = MCSoundCategory.valueOf(args[1].val().toUpperCase()); + } catch (IllegalArgumentException ex) { + throw new CREFormatException("Sound category '" + args[1].val() + "' is invalid.", t); + } + p.stopSound(category); + return CVoid.VOID; + } + + @Override + public String getName() { + return "stop_sound_category"; + } + + @Override + public Integer[] numArgs() { + return new Integer[]{2}; + } + + @Override + public String docs() { + return "void {player, category} Stops all sounds in a category for the given player. (MC 1.19)"; + } + + @Override + public MSVersion since() { + return MSVersion.V3_3_5; + } + } + @api(environments = {CommandHelperEnvironment.class}) @seealso({com.laytonsmith.core.functions.Environment.play_named_sound.class}) public static class stop_named_sound extends AbstractFunction {