2019-12-17 12:37:59 +00:00
|
|
|
package pw.kaboom.extras.commands;
|
2019-07-30 14:41:54 +00:00
|
|
|
|
2022-05-21 19:28:42 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
2019-07-30 14:41:54 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
2022-12-27 17:50:02 +00:00
|
|
|
import pw.kaboom.extras.skin.SkinManager;
|
2019-12-17 12:37:59 +00:00
|
|
|
|
2022-05-21 19:28:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2023-04-01 23:25:41 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2022-05-21 19:28:42 +00:00
|
|
|
|
2019-12-21 13:39:31 +00:00
|
|
|
public final class CommandSkin implements CommandExecutor {
|
2022-12-27 17:50:02 +00:00
|
|
|
private final Map<Player, Long> lastUsedMillis = new HashMap<>();
|
2022-05-20 02:35:48 +00:00
|
|
|
|
|
|
|
@Override
|
2022-05-21 19:28:42 +00:00
|
|
|
public boolean onCommand(final @Nonnull CommandSender sender,
|
|
|
|
final @Nonnull Command command,
|
|
|
|
final @Nonnull String label,
|
2022-05-20 03:07:38 +00:00
|
|
|
final String[] args) {
|
2023-04-01 23:25:41 +00:00
|
|
|
if (!(sender instanceof final Player player)) {
|
2022-05-21 19:28:42 +00:00
|
|
|
sender.sendMessage(Component
|
|
|
|
.text("Command has to be run by a player"));
|
2022-10-16 00:08:32 +00:00
|
|
|
return true;
|
2022-05-20 02:35:48 +00:00
|
|
|
}
|
2022-10-16 00:08:32 +00:00
|
|
|
|
2022-12-27 17:50:02 +00:00
|
|
|
final long millis = lastUsedMillis.getOrDefault(player, 0L);
|
2022-10-16 00:08:32 +00:00
|
|
|
final long millisDifference = System.currentTimeMillis() - millis;
|
|
|
|
|
|
|
|
if (args.length == 0) {
|
|
|
|
player.sendMessage(Component
|
2023-02-02 08:20:10 +00:00
|
|
|
.text("Usage: /" + label + " <username>\n/" + label + " off",
|
2022-10-16 00:08:32 +00:00
|
|
|
NamedTextColor.RED));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (millisDifference <= 2000) {
|
|
|
|
player.sendMessage(Component
|
|
|
|
.text("Please wait a few seconds before changing your skin"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-12-27 17:50:02 +00:00
|
|
|
lastUsedMillis.put(player, System.currentTimeMillis());
|
|
|
|
|
2022-10-16 00:08:32 +00:00
|
|
|
final String name = args[0];
|
|
|
|
|
2022-12-27 17:50:02 +00:00
|
|
|
if (name.equalsIgnoreCase("off") || name.equalsIgnoreCase("remove")
|
|
|
|
|| name.equalsIgnoreCase("disable")) {
|
|
|
|
SkinManager.resetSkin(player, true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name.equalsIgnoreCase("auto") || name.equalsIgnoreCase("default")
|
|
|
|
|| name.equalsIgnoreCase("reset")) {
|
|
|
|
SkinManager.applySkin(player, player.getName(), true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final boolean shouldSendMessage = true;
|
2022-10-16 00:08:32 +00:00
|
|
|
|
2022-12-27 17:50:02 +00:00
|
|
|
SkinManager.applySkin(player, name, shouldSendMessage);
|
2022-05-20 02:35:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-07-30 14:41:54 +00:00
|
|
|
}
|