QoL/src/main/java/xyz/etztech/qol/commands/ShadowMuteCommand.java

74 lines
2.3 KiB
Java
Raw Normal View History

2018-09-12 15:53:47 +00:00
package xyz.etztech.qol.commands;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import xyz.etztech.qol.EtzTechUtil;
import xyz.etztech.qol.Lang;
import xyz.etztech.qol.QoL;
2020-10-02 22:24:09 +00:00
import xyz.etztech.core.command.TickDuration;
import java.time.Duration;
2018-09-12 15:53:47 +00:00
public class ShadowMuteCommand implements CommandExecutor {
QoL plugin;
public ShadowMuteCommand(QoL paramQoL) {
2018-09-12 15:53:47 +00:00
this.plugin = paramQoL;
plugin.getCommand("shadowmute").setExecutor(this);
2018-09-12 15:53:47 +00:00
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!commandSender.hasPermission("qol.shadowmute")) {
EtzTechUtil.sms(commandSender, Lang.NO_PERMISSION.getDef());
return true;
}
if (args.length < 2) {
EtzTechUtil.sms(commandSender, ChatColor.RED + "/sm <player> <time>");
EtzTechUtil.sms(commandSender, ChatColor.RED + "Time Format: 1h2m3s (1 hour, 2 minutes, and 3 seconds)");
return true;
}
Player argPlayer = Bukkit.getPlayer(args[0]);
2018-09-12 15:53:47 +00:00
if (argPlayer == null) {
EtzTechUtil.sms(commandSender, ChatColor.RED + "No player found.");
return true;
}
2018-09-12 15:53:47 +00:00
final Player player = argPlayer;
2020-10-02 22:24:09 +00:00
TickDuration duration;
2018-09-12 15:53:47 +00:00
try {
2020-10-02 22:24:09 +00:00
duration = TickDuration.parse(args[1]);
2018-09-12 15:53:47 +00:00
} catch (Exception ex) {
2020-10-02 22:24:09 +00:00
duration = new TickDuration(Duration.ofMinutes(5));
2018-09-12 15:53:47 +00:00
commandSender.sendMessage(ChatColor.RED + ex.getMessage());
}
EtzTechUtil.sms(commandSender, ChatColor.GREEN + "Shadow Muting " + ChatColor.YELLOW +
2020-10-02 22:24:09 +00:00
player.getName() + ChatColor.GREEN + " for " + ChatColor.YELLOW + duration.toString());
2018-09-12 15:53:47 +00:00
QoL.addSM(player);
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Removing Shadow Mute for " + ChatColor.YELLOW + player.getName());
QoL.removeSM(player);
}
2020-10-02 22:24:09 +00:00
}, duration.toTicks());
2018-09-12 15:53:47 +00:00
return true;
}
}