mirror of
https://github.com/kaboomserver/extras.git
synced 2025-07-24 14:33:47 +00:00
Reduce code duplication
This commit is contained in:
parent
551f9f4807
commit
a998fa8321
4 changed files with 65 additions and 102 deletions
|
@ -9,16 +9,6 @@ import org.bukkit.command.ConsoleCommandSender;
|
|||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import com.destroystokyo.paper.profile.ProfileProperty;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
class CommandUsername implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, final String[] args) {
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
|
@ -29,35 +19,13 @@ class CommandUsername implements CommandExecutor {
|
|||
if (args.length == 0) {
|
||||
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
||||
} else if (!Main.usernameInProgress.contains(player.getUniqueId())) {
|
||||
Main.usernameInProgress.add(player.getUniqueId());
|
||||
|
||||
final String nameColor = ChatColor.translateAlternateColorCodes('&', String.join(" ", args));
|
||||
final String nameShort = nameColor.substring(0, Math.min(16, nameColor.length()));
|
||||
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
final PlayerProfile profile = player.getPlayerProfile();
|
||||
profile.setName(nameShort);
|
||||
|
||||
SkinDownloader skinDownloader = new SkinDownloader();
|
||||
|
||||
if (skinDownloader.fetchSkinData(args[0])) {
|
||||
final String texture = skinDownloader.getTexture();
|
||||
final String signature = skinDownloader.getSignature();
|
||||
|
||||
profile.setProperty(new ProfileProperty("textures", texture, signature));
|
||||
}
|
||||
|
||||
player.sendMessage("Successfully set your username to \"" + nameShort + "\"");
|
||||
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
player.setPlayerProfile(profile);
|
||||
Main.usernameInProgress.remove(player.getUniqueId());
|
||||
}
|
||||
}.runTask(JavaPlugin.getPlugin(Main.class));
|
||||
}
|
||||
}.runTaskAsynchronously(JavaPlugin.getPlugin(Main.class));
|
||||
final String name = nameColor.substring(0, Math.min(16, nameColor.length()));
|
||||
final boolean shouldChangeUsername = true;
|
||||
final boolean shouldSendMessage = true;
|
||||
|
||||
SkinDownloader skinDownloader = new SkinDownloader();
|
||||
skinDownloader.applySkin(player, name, shouldChangeUsername, shouldSendMessage);
|
||||
} else {
|
||||
player.sendMessage("Your username is already being changed. Please wait a few seconds.");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue