Fix & improve skin command, improve username command (#331)

* Use per-player ratelimit for /username

* Improve the skin system

- Migrates skin getting over to Mojang. I do indeed understand that the Mojang API is more ratelimited and generally harder to use, it should be noted that it has an almost 0% chance of error. Compare that to Ashcon which, on some days, has a 50% chance of actually recognizing your account exists
- Uses CompletableFutures and a ExecutorService for making requests
- Renames SkinDownloader class to SkinManager class
- Makes SkinManager class static
- Limits the /skin command per-player
This commit is contained in:
Allink 2022-12-27 17:50:02 +00:00 committed by GitHub
parent 411cdaa104
commit cbbc4937d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 252 additions and 129 deletions

View file

@ -1,6 +1,8 @@
package pw.kaboom.extras.commands;
import com.destroystokyo.paper.profile.PlayerProfile;
import java.util.HashMap;
import java.util.Map;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
@ -14,7 +16,7 @@ import org.bukkit.entity.Player;
import javax.annotation.Nonnull;
public final class CommandUsername implements CommandExecutor {
private long millis;
private final Map<Player, Long> lastUsedMillis = new HashMap<>();
@Override
public boolean onCommand(final @Nonnull CommandSender sender,
@ -31,6 +33,7 @@ public final class CommandUsername implements CommandExecutor {
final String nameColor = ChatColor.translateAlternateColorCodes(
'&', String.join(" ", args));
final String name = nameColor.substring(0, Math.min(16, nameColor.length()));
final long millis = lastUsedMillis.getOrDefault(player, 0L);
final long millisDifference = System.currentTimeMillis() - millis;
if (args.length == 0) {
@ -62,7 +65,7 @@ public final class CommandUsername implements CommandExecutor {
profile.setName(name); // FIXME: Marked for removal
player.setPlayerProfile(profile);
millis = System.currentTimeMillis();
lastUsedMillis.put(player, System.currentTimeMillis());
player.sendMessage(
Component.text("Successfully set your username to \"")