Add /grabhead and use local skins if possible with skinapi

This commit is contained in:
libraryaddict 2020-06-20 09:26:48 +12:00
parent 53051668af
commit 4fa20a0367
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
7 changed files with 167 additions and 2 deletions

View File

@ -162,6 +162,7 @@ public class LibsDisguises extends JavaPlugin {
registerCommand("copydisguise", new CopyDisguiseCommand());
registerCommand("grabskin", new GrabSkinCommand());
registerCommand("savedisguise", new SaveDisguiseCommand());
registerCommand("grabhead", new GrabHeadCommand());
} else {
getLogger().info("Commands has been disabled, as per config");
}

View File

@ -0,0 +1,129 @@
package me.libraryaddict.disguise.commands.utils;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.SkinUtils;
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import java.lang.reflect.Field;
/**
* Created by libraryaddict on 20/06/2020.
*/
public class GrabHeadCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] strings) {
if (sender instanceof Player && !sender.isOp() &&
(!LibsPremium.isPremium() || LibsPremium.getPaidInformation() == LibsPremium.getPluginInformation())) {
sender.sendMessage(ChatColor.RED + "Please purchase Lib's Disguises to enable player commands");
return true;
}
if (!sender.hasPermission("libsdisguises.grabhead")) {
sender.sendMessage(LibsMsg.NO_PERM.get());
return true;
}
if (!(sender instanceof Player)) {
sender.sendMessage(LibsMsg.NO_CONSOLE.get());
return true;
}
if (strings.length == 0) {
sendHelp(sender);
return true;
}
String[] args = DisguiseUtilities.split(StringUtils.join(strings, " "));
String skin = args[0];
String usable = SkinUtils.getUsableStatus();
if (usable != null) {
sender.sendMessage(usable);
return true;
}
SkinUtils.SkinCallback callback = new SkinUtils.SkinCallback() {
private BukkitTask runnable = new BukkitRunnable() {
@Override
public void run() {
sender.sendMessage(LibsMsg.PLEASE_WAIT.get());
}
}.runTaskTimer(LibsDisguises.getInstance(), 100, 100);
@Override
public void onError(LibsMsg msg, Object... args) {
sender.sendMessage(msg.get(args));
runnable.cancel();
}
@Override
public void onInfo(LibsMsg msg, Object... args) {
sender.sendMessage(msg.get(args));
}
@Override
public void onSuccess(WrappedGameProfile profile) {
runnable.cancel();
DisguiseUtilities.setGrabHeadCommandUsed();
new BukkitRunnable() {
@Override
public void run() {
ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
SkullMeta meta = (SkullMeta) skull.getItemMeta();
try {
Field field = meta.getClass().getDeclaredField("profile");
field.setAccessible(true);
field.set(meta, profile.getHandle());
}
catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
skull.setItemMeta(meta);
((Player) sender).getInventory().addItem(skull);
sender.sendMessage(LibsMsg.GRAB_HEAD_SUCCESS.get());
}
}.runTask(LibsDisguises.getInstance());
}
};
SkinUtils.grabSkin(skin, callback);
return true;
}
private void sendHelp(CommandSender sender) {
sender.sendMessage(LibsMsg.GRAB_DISG_HELP_1.get());
sender.sendMessage(LibsMsg.GRAB_DISG_HELP_2.get());
sender.sendMessage(LibsMsg.GRAB_DISG_HELP_3.get());
sender.sendMessage(LibsMsg.GRAB_DISG_HELP_4.get());
sender.sendMessage(LibsMsg.GRAB_DISG_HELP_5.get());
sender.sendMessage(LibsMsg.GRAB_DISG_HELP_6.get());
}
}

View File

@ -133,7 +133,7 @@ public class DisguiseUtilities {
private static Gson gson;
@Getter
private static boolean pluginsUsed, commandsUsed, copyDisguiseCommandUsed, grabSkinCommandUsed,
saveDisguiseCommandUsed;
saveDisguiseCommandUsed, grabHeadCommandUsed;
private static long libsDisguisesCalled;
/**
* Keeps track of what tick this occured
@ -173,6 +173,10 @@ public class DisguiseUtilities {
grabSkinCommandUsed = true;
}
public static void setGrabHeadCommandUsed() {
grabHeadCommandUsed = true;
}
public static void setCopyDisguiseCommandUsed() {
copyDisguiseCommandUsed = true;
}

View File

@ -213,7 +213,16 @@ public class SkinUtils {
}
}
WrappedGameProfile profile = DisguiseUtilities.getGameProfile(param);
if (profile != null) {
callback.onInfo(LibsMsg.SKIN_API_USING_EXISTING_NAME);
callback.onSuccess(profile);
return;
}
callback.onInfo(LibsMsg.SKIN_API_USING_NAME);
handleName(param, modelType, callback);
}
}

View File

@ -81,6 +81,13 @@ public class MetricsInitalizer {
}
});
metrics.addCustomChart(new Metrics.SimplePie("grabhead_command") {
@Override
public String getValue() {
return "" + DisguiseUtilities.isGrabHeadCommandUsed();
}
});
metrics.addCustomChart(new Metrics.SimplePie("save_disguise_command") {
@Override
public String getValue() {

View File

@ -233,6 +233,7 @@ public enum LibsMsg {
SKIN_API_USING_FILE(ChatColor.GRAY + "File provided and found, now attempting to upload to mineskin.org"),
SKIN_API_INVALID_NAME(ChatColor.RED + "Invalid name/file/uuid provided!"),
SKIN_API_USING_UUID(ChatColor.GRAY + "UUID successfully parsed, now attempting to connect to mineskin.org"),
SKIN_API_USING_EXISTING_NAME(ChatColor.GRAY + "Found a saved skin under that name locally! Using that!"),
SKIN_API_USING_NAME(
ChatColor.GRAY + "Determined to be player name, now attempting to validate and connect to mineskin.org"),
SAVE_DISG_HELP_1(ChatColor.GREEN + "The <DisguiseName> is what the disguise will be called in Lib's Disguises"),
@ -257,6 +258,11 @@ public enum LibsMsg {
ChatColor.GREEN + "If you want the slim Alex version of the skin, append :slim. So 'myskin.png:slim'"),
GRAB_DISG_HELP_6(
ChatColor.GREEN + "You will be sent the skin data, but you can also use the saved names in disguises"),
GRAB_HEAD_SUCCESS(ChatColor.GREEN + "Head successfully grabbed and added to inventory!"),
GRAB_HEAD_HELP_1(ChatColor.GREEN + "Grab the head of a file, player or url! This is a Lib's Disguises feature."),
GRAB_HEAD_HELP_2(ChatColor.DARK_GREEN + "/grabhead https://somesite.com/myskin.png"),
GRAB_HEAD_HELP_3(ChatColor.DARK_GREEN + "/grabhead myskin.png - Skins must be in the folder!"),
GRAB_HEAD_HELP_4(ChatColor.DARK_GREEN + "/grabhead <Player name or UUID>"),
CUSTOM_DISGUISE_NAME_CONFLICT(
ChatColor.RED + "Cannot create the custom disguise '%s' as there is a name conflict!"),
ERROR_LOADING_CUSTOM_DISGUISE(ChatColor.RED + "Error while loading custom disguise '%s'%s"),

View File

@ -84,6 +84,10 @@ commands:
aliases: [customdisguise, savedisg, customdisg, createdisguise, createdisg]
permission: libsdisguises.seecmd.savedisguise
description: Save a custom disguise to disguises.yml
grabhead:
aliases: [grabskull, playerhead, savehead, gethead]
permission: libsdisguises.seecmd.grabhead
description: Grab the head item of a skin, url or player
permissions:
libsdisguises.reload:
@ -123,6 +127,8 @@ permissions:
default: false
libsdisguises.multiname:
description: Allows the command user to set names on different heights
libsdisguises.grabhead:
description: Allows the command user to use /grabhead
libsdisguises.seecmd:
description: See all commands in tab-completion
default: true
@ -145,6 +151,7 @@ permissions:
libsdisguises.seecmd.copydisguise: true
libsdisguises.seecmd.grabskin: true
libsdisguises.seecmd.savedisguise: true
libsdisguises.seecmd.grabhead: true
libsdisguises.seecmd.disguiseviewself:
description: See the /disguiseviewself command in tab-completion
libsdisguises.seecmd.disguise:
@ -180,4 +187,6 @@ permissions:
libsdisguises.seecmd.grabskin:
description: See the /grabskin command in tab-completion
libsdisguises.seecmd.savedisguise:
description: See the /savedisguise command in tab-completion
description: See the /savedisguise command in tab-completion
libsdisguises.seecmd.grabhead:
description: See the /grabhead command in tab-completion