2019-07-30 14:41:54 +00:00
|
|
|
package pw.kaboom.extras;
|
|
|
|
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2019-09-22 02:37:43 +00:00
|
|
|
import org.bukkit.command.ConsoleCommandSender;
|
2019-07-30 14:41:54 +00:00
|
|
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2019-09-28 00:29:48 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2019-07-30 14:41:54 +00:00
|
|
|
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) {
|
2019-09-22 02:37:43 +00:00
|
|
|
if (sender instanceof ConsoleCommandSender) {
|
|
|
|
sender.sendMessage("Command has to be run by a player");
|
2019-07-30 14:41:54 +00:00
|
|
|
} else {
|
2019-09-22 02:37:43 +00:00
|
|
|
final Player player = (Player) sender;
|
|
|
|
|
|
|
|
if (args.length == 0) {
|
|
|
|
player.sendMessage(ChatColor.RED + "Usage: /" + label + " <username>");
|
2019-09-28 18:22:18 +00:00
|
|
|
} 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()));
|
|
|
|
|
2019-12-02 16:12:05 +00:00
|
|
|
new BukkitRunnable() {
|
|
|
|
public void run() {
|
|
|
|
final PlayerProfile profile = player.getPlayerProfile();
|
|
|
|
profile.setName(nameShort);
|
2019-09-28 18:22:18 +00:00
|
|
|
|
2019-12-02 16:12:05 +00:00
|
|
|
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));
|
2019-09-28 18:22:18 +00:00
|
|
|
}
|
2019-12-02 16:12:05 +00:00
|
|
|
|
|
|
|
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));
|
2019-09-28 18:22:18 +00:00
|
|
|
} else {
|
|
|
|
player.sendMessage("Your username is already being changed. Please wait a few seconds.");
|
2019-09-22 02:37:43 +00:00
|
|
|
}
|
2019-07-30 14:41:54 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|