diff options
author | Luke Anderson (stuntguy3000) <stuntguy3000@gmail.com> | 2014-02-05 22:46:50 +1030 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2014-02-08 00:25:34 +0000 |
commit | 5c74af42a3c5f204aea7b95655fbbb599960a226 (patch) | |
tree | 8d483e7cd43da40411c03e90be4d7f1c810d02e6 | |
parent | ce48f2f326e6c2af511d722a2ae5c8084665b219 (diff) | |
download | Essentials-5c74af42a3c5f204aea7b95655fbbb599960a226.tar Essentials-5c74af42a3c5f204aea7b95655fbbb599960a226.tar.gz Essentials-5c74af42a3c5f204aea7b95655fbbb599960a226.tar.lz Essentials-5c74af42a3c5f204aea7b95655fbbb599960a226.tar.xz Essentials-5c74af42a3c5f204aea7b95655fbbb599960a226.zip |
Add /skull command
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandskull.java | 84 | ||||
-rw-r--r-- | Essentials/src/messages.properties | 5 | ||||
-rw-r--r-- | Essentials/src/plugin.yml | 4 |
3 files changed, 93 insertions, 0 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandskull.java b/Essentials/src/com/earth2me/essentials/commands/Commandskull.java new file mode 100644 index 000000000..eeac3c668 --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/commands/Commandskull.java @@ -0,0 +1,84 @@ +package com.earth2me.essentials.commands; + +import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.User; +import com.earth2me.essentials.utils.LocationUtil; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.block.BlockState; +import org.bukkit.block.Skull; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; + +public class Commandskull extends EssentialsCommand +{ + public Commandskull() + { + super("skull"); + } + + @Override + protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception + { + if (args.length < 1) + { + user.getInventory().addItem(spawnSkull(user.getName(), 1)); + user.sendMessage(_("givenSkull", user.getName())); + } else { + // Alphanumeric and underscores only + if (!args[0].matches("^[A-Za-z0-9_]+$")) { + throw new IllegalArgumentException(_("invalidSkullOwner")); + } + + final Location target = LocationUtil.getTarget(user.getBase()); + BlockState state = target.getBlock().getState(); + Skull skull = null; + + if (state instanceof Skull) + { + skull = (Skull) state; + if (skull.hasOwner() && !user.isAuthorized("essentials.skull.change")) + { + throw new Exception(_("noPermissionSkull")); + } + + user.sendMessage(_("skullChanged", args[0])); + + skull.setOwner(args[0]); + skull.update(true); + return; + } + + if (skull == null) + { + ItemStack cSkull = user.getItemInHand(); + if (cSkull.getType() == Material.SKULL_ITEM && cSkull.getDurability() == 3) { + SkullMeta cSkullMeta = (SkullMeta) cSkull.getItemMeta(); + if (cSkullMeta.hasOwner() && !user.isAuthorized("essentials.skull.change")) + { + throw new Exception(_("noPermissionSkull")); + } + + user.sendMessage(_("skullChanged", args[0])); + user.setItemInHand(spawnSkull(args[0], cSkull.getAmount())); + } else { + throw new Exception(_("invalidSkull")); + } + } + } + } + + private ItemStack spawnSkull(String owner, int amount) { + if (amount < 1 || amount > 64) { + amount = 1; + } + ItemStack skull = new ItemStack(Material.SKULL_ITEM, amount, (byte) 3); + SkullMeta skullMeta = (SkullMeta) skull.getItemMeta(); + skullMeta.setDisplayName("§fSkull of " + owner); + skullMeta.setOwner(owner); + skull.setItemMeta(skullMeta); + return skull; + } +}
\ No newline at end of file diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 68a931e66..54a5d5f98 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -535,3 +535,8 @@ ignoreExempt=\u00a74You can not ignore that player. unsafeTeleportDestination=\u00a74The teleport destination is unsafe and teleport-safety is disabled. noMetaJson=JSON Metadata is not supported in this version of Bukkit. maxMoney=\u00a74This transaction would exceed the balance limit for this account. +skullChanged=\u00a76Skull owner set to \u00a7c{0}.\u00a76. +invalidSkullOwner=\u00a74Skull owners names can only contain letters, numbers and underscores. +givenSkull=\u00a76You have been given the Skull of \u00a7c{0}\u00a76. +noPermissionSkull=\u00a74You do not have permission to spawn/modify that Skull. +invalidSkull=\u00a74Please hold or look at a player Skull.
\ No newline at end of file diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index 3eb2b6201..b2c0cfe3d 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -326,6 +326,10 @@ commands: description: Creates a jail where you specified named [jailname]. usage: /<command> <jailname> aliases: [esetjail,createjail,ecreatejail] + skull: + description: Give yourself or change the owner of a Skull. + usage: /<command> [owner] + aliases: [eskull, egiveskull, giveskull] setwarp: description: Creates a new warp. usage: /<command> <warp> |