From 38e42f9f90f3fc2a38a4c40d9ecb1ef643cc3c13 Mon Sep 17 00:00:00 2001 From: Yurakaii <78126278+Yurakaii@users.noreply.github.com> Date: Sun, 24 Nov 2024 20:42:04 -0500 Subject: [PATCH] Add argument to /skull to give skull to other player (#5822) Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com> --- .../essentials/commands/Commandskull.java | 28 +++++++++++++++---- .../src/main/resources/messages.properties | 7 ++++- Essentials/src/main/resources/plugin.yml | 2 +- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandskull.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandskull.java index d914cdfb916..e91a3addbf6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandskull.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandskull.java @@ -48,7 +48,14 @@ public Commandskull() { @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { final String owner; - if (args.length > 0 && user.isAuthorized("essentials.skull.others")) { + final User player; + if (args.length == 2) { + player = getPlayer(server, args, 1, false, false); + } else { + player = user; + } + + if (args.length > 0 && player.isAuthorized("essentials.skull.others")) { if (BASE_64_PATTERN.matcher(args[0]).matches()) { try { final String decoded = new String(Base64.getDecoder().decode(args[0])); @@ -80,7 +87,7 @@ protected void run(final Server server, final User user, final String commandLab final SkullMeta metaSkull; boolean spawn = false; - if (itemSkull != null && MaterialUtil.isPlayerHead(itemSkull)) { + if (itemSkull != null && MaterialUtil.isPlayerHead(itemSkull) && user == player) { metaSkull = (SkullMeta) itemSkull.getItemMeta(); } else if (user.isAuthorized("essentials.skull.spawn")) { itemSkull = new ItemStack(SKULL_ITEM, 1, (byte) 3); @@ -94,10 +101,10 @@ protected void run(final Server server, final User user, final String commandLab throw new TranslatableException("noPermissionSkull"); } - editSkull(user, itemSkull, metaSkull, owner, spawn); + editSkull(user, player, itemSkull, metaSkull, owner, spawn); } - private void editSkull(final User user, final ItemStack stack, final SkullMeta skullMeta, final String owner, final boolean spawn) { + private void editSkull(final User user, final User receive, final ItemStack stack, final SkullMeta skullMeta, final String owner, final boolean spawn) { ess.runTaskAsynchronously(() -> { // Run this stuff async because it causes an HTTP request @@ -131,8 +138,11 @@ private void editSkull(final User user, final ItemStack stack, final SkullMeta s ess.scheduleSyncDelayedTask(() -> { stack.setItemMeta(skullMeta); if (spawn) { - Inventories.addItem(user.getBase(), stack); - user.sendTl("givenSkull", shortOwnerName); + Inventories.addItem(receive.getBase(), stack); + receive.sendTl("givenSkull", shortOwnerName); + if (user != receive) { + user.sendTl("givenSkullOther", receive.getDisplayName(), shortOwnerName); + } return; } user.sendTl("skullChanged", shortOwnerName); @@ -148,6 +158,12 @@ protected List getTabCompleteOptions(final Server server, final User use } else { return Lists.newArrayList(user.getName()); } + } else if (args.length == 2){ + if (user.isAuthorized("essentials.skull.others")) { + return getPlayers(server, user); + } else { + return Lists.newArrayList(user.getName()); + } } else { return Collections.emptyList(); } diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index 760a07977a5..bea0f41516d 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -454,6 +454,7 @@ geoIpLicenseMissing=No license key found\! Please visit https\://essentialsx.net geoIpUrlEmpty=GeoIP download url is empty. geoIpUrlInvalid=GeoIP download url is invalid. givenSkull=You have been given the skull of {0}. +givenSkullOther=You have given {0} the skull of {1}. godCommandDescription=Enables your godly powers. godCommandUsage=/ [player] [on|off] godCommandUsage1=/ [player] @@ -1208,13 +1209,17 @@ south=S southWest=SW skullChanged=Skull changed to {0}. skullCommandDescription=Set the owner of a player skull -skullCommandUsage=/ [owner] +skullCommandUsage=/ [owner] [player] skullCommandUsage1=/ skullCommandUsage1Description=Gets your own skull skullCommandUsage2=/ skullCommandUsage2Description=Gets the skull of the specified player skullCommandUsage3=/ skullCommandUsage3Description=Gets a skull with the specified texture (either the hash from a texture URL or a Base64 texture value) +skullCommandUsage4=/ +skullCommandUsage4Description=Gives a skull of the specified owner to a specified player +skullCommandUsage5=/ +skullCommandUsage5Description=Gives a skull with the specified texture (either the hash from a texture URL or a Base64 texture value) to a specified player skullInvalidBase64=The texture value is invalid. slimeMalformedSize=Malformed size. smithingtableCommandDescription=Opens up a smithing table. diff --git a/Essentials/src/main/resources/plugin.yml b/Essentials/src/main/resources/plugin.yml index 51af179a95f..8efb209ad23 100644 --- a/Essentials/src/main/resources/plugin.yml +++ b/Essentials/src/main/resources/plugin.yml @@ -446,7 +446,7 @@ commands: aliases: [sign, esign, eeditsign] skull: description: Set the owner of a player skull - usage: / [owner] + usage: / [owner] [player] aliases: [eskull, playerskull, eplayerskull, head, ehead] smithingtable: description: Opens up a smithing table.