TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stopsound.java

73 lines
2.0 KiB
Java
Raw Normal View History

2020-01-10 01:02:28 +00:00
package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Stops all sounds or a specified sound.", usage = "/<command> [sound]")
2020-01-10 01:02:28 +00:00
public class Command_stopsound extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length > 0)
{
Sound sound = null;
for (Sound loop : Sound.values())
2020-01-10 01:02:28 +00:00
{
if (loop != null && loop.name().equalsIgnoreCase(args[0]))
{
sound = Sound.valueOf(args[0].toUpperCase());
break;
}
2020-01-10 01:02:28 +00:00
}
if (sound == null)
2020-01-10 01:02:28 +00:00
{
msg(args[0] + " is not a valid sound.", ChatColor.RED);
return true;
2020-01-10 01:02:28 +00:00
}
playerSender.stopSound(sound);
msg("Stopped all " + sound.name() + " sounds", ChatColor.GREEN);
return true;
2020-01-10 01:02:28 +00:00
}
for (Sound sound : Sound.values())
{
playerSender.stopSound(sound);
2020-01-10 01:02:28 +00:00
}
msg("Stopped all sounds.", ChatColor.GREEN);
2020-01-10 01:02:28 +00:00
return true;
}
@Override
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
{
if (args.length == 1)
{
return soundList();
}
return Collections.emptyList();
}
public List<String> soundList()
{
List<String> sounds = new ArrayList<>();
for (Sound sound : Sound.values())
{
sounds.add(sound.name());
}
return sounds;
}
}