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

72 lines
2.1 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;
import xyz.etztech.qol.other.ShadowMuteTime;
public class ShadowMuteCommand implements CommandExecutor {
QoL plugin;
public ShadowMuteCommand(QoL paramQoL)
{
this.plugin = paramQoL;
}
@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;
ShadowMuteTime smt;
try {
smt = ShadowMuteTime.parse(args[1]);
} catch (Exception ex) {
smt = new ShadowMuteTime();
commandSender.sendMessage(ChatColor.RED + ex.getMessage());
}
EtzTechUtil.sms(commandSender, ChatColor.GREEN + "Shadow Muting " + ChatColor.YELLOW +
player.getName() + ChatColor.GREEN + " for " + ChatColor.YELLOW + smt.toString());
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);
}
}, smt.toTicks());
return true;
}
}