Skip to content

Commit

Permalink
Add stop_sound_category()
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Apr 2, 2024
1 parent 2955b57 commit b92ea87
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/PlayerManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends CREThrowable>[] 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 {
Expand Down

0 comments on commit b92ea87

Please sign in to comment.