82 lines
2.8 KiB
Java
82 lines
2.8 KiB
Java
package net.mindoverflow.kissplugin.commands;
|
|
|
|
import net.mindoverflow.kissplugin.Main;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.time.LocalTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
public class AngryCommand implements CommandExecutor
|
|
{
|
|
|
|
private Main plugin;
|
|
public AngryCommand(Main plugin)
|
|
{
|
|
this.plugin = plugin;
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
|
|
|
|
if(commandSender instanceof Player)
|
|
{
|
|
Player sender = (Player)commandSender;
|
|
|
|
if(plugin.runningTask.angryPlayers.containsKey(sender.getName()))
|
|
{
|
|
noLongerAngry(sender.getName(), plugin);
|
|
return true;
|
|
}
|
|
|
|
int howLong = 60;
|
|
if(args.length == 0)
|
|
{
|
|
plugin.runningTask.angryPlayers.put(sender.getName(), howLong * plugin.runningTask.multiplier);
|
|
|
|
|
|
LocalTime timeOfDay = LocalTime.ofSecondOfDay(howLong);
|
|
String time = timeOfDay.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
|
|
|
|
time = time.replaceFirst(":", " hours, ");
|
|
time = time.replaceFirst(":", " minutes, and ");
|
|
time = time + " seconds";
|
|
sender.sendMessage("§7You will be angry for §c" + time + "§7!");
|
|
sender.sendMessage("§7You did not specify for how long! Use §c/angry <seconds>§7 to set a specific time.");
|
|
}
|
|
else
|
|
{
|
|
howLong = Integer.parseInt(args[0]);
|
|
if(howLong > 86399) howLong = 86399;
|
|
plugin.runningTask.angryPlayers.put(sender.getName(), howLong * plugin.runningTask.multiplier);
|
|
|
|
|
|
LocalTime timeOfDay = LocalTime.ofSecondOfDay(howLong);
|
|
String time = timeOfDay.format(DateTimeFormatter.ofPattern("HH:mm:ss"));
|
|
time = time.replaceFirst(":", " hours, ");
|
|
time = time.replaceFirst(":", " minutes, and ");
|
|
time = time + " seconds";
|
|
sender.sendMessage("§7You will be angry for §c" + time + "§7!");
|
|
}
|
|
|
|
plugin.getServer().broadcastMessage("§c" + sender.getName() + "§e is now angry!");
|
|
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public static void noLongerAngry(String playerName, Main plugin)
|
|
{
|
|
|
|
plugin.runningTask.angryPlayers.remove(playerName);
|
|
plugin.getServer().broadcastMessage("§a" + playerName + "§e is no longer angry!");
|
|
|
|
Player player = plugin.getServer().getPlayer(playerName);
|
|
if(player == null) return;
|
|
player.sendMessage("§aYou are no longer angry!");
|
|
}
|
|
}
|