Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add give argument to skull command #5822

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,18 @@ 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){
try{
player = getPlayer(server, args[1], true, false);
} catch (final Exception e) {
throw new TranslatableException("playerNotFound");
}
} 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]));
Expand All @@ -73,28 +84,28 @@ protected void run(final Server server, final User user, final String commandLab
owner = args[0];
}
} else {
owner = user.getName();
owner = player.getName();
}

ItemStack itemSkull = user.getItemInHand();
ItemStack itemSkull = player.getItemInHand();
final SkullMeta metaSkull;
boolean spawn = false;

if (itemSkull != null && MaterialUtil.isPlayerHead(itemSkull)) {
metaSkull = (SkullMeta) itemSkull.getItemMeta();
} else if (user.isAuthorized("essentials.skull.spawn")) {
} else if (player.isAuthorized("essentials.skull.spawn")) {
itemSkull = new ItemStack(SKULL_ITEM, 1, (byte) 3);
metaSkull = (SkullMeta) itemSkull.getItemMeta();
spawn = true;
} else {
throw new TranslatableException("invalidSkull");
}

if (metaSkull.hasOwner() && !user.isAuthorized("essentials.skull.modify")) {
if (metaSkull.hasOwner() && !player.isAuthorized("essentials.skull.modify")) {
throw new TranslatableException("noPermissionSkull");
}

editSkull(user, itemSkull, metaSkull, owner, spawn);
editSkull(player, itemSkull, metaSkull, owner, spawn);
}

private void editSkull(final User user, final ItemStack stack, final SkullMeta skullMeta, final String owner, final boolean spawn) {
Expand Down Expand Up @@ -148,6 +159,12 @@ protected List<String> 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();
}
Expand Down
2 changes: 1 addition & 1 deletion Essentials/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ commands:
aliases: [sign, esign, eeditsign]
skull:
description: Set the owner of a player skull
usage: /<command> [owner]
usage: /<command> [owner] [player]
aliases: [eskull, playerskull, eplayerskull, head, ehead]
smithingtable:
description: Opens up a smithing table.
Expand Down