CommandSkull.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package me.km.commands;
  2. import com.mojang.authlib.GameProfile;
  3. import me.km.KajetansMod;
  4. import me.km.api.GlobalText;
  5. import me.km.utils.ItemStackBuilder;
  6. import me.km.api.Module;
  7. import me.km.api.ModuleCommand;
  8. import me.km.permissions.Permissions;
  9. import net.minecraft.block.Block;
  10. import net.minecraft.command.ICommandSender;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.init.Items;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.nbt.NBTTagCompound;
  15. import net.minecraft.nbt.NBTUtil;
  16. import net.minecraft.tileentity.TileEntitySkull;
  17. public class CommandSkull extends ModuleCommand
  18. {
  19. public CommandSkull(Module m)
  20. {
  21. super("skull", m);
  22. super.setDescription("Gibt dir den Kopf eines Spielers");
  23. super.setUsage("/skull <owner>");
  24. super.setPermission(Permissions.SKULL);
  25. }
  26. @Override
  27. public boolean execute(ICommandSender cs, String[] arg)
  28. {
  29. if(!(cs instanceof EntityPlayer))
  30. {
  31. this.getModule().send(cs, GlobalText.onlyPlayer());
  32. return true;
  33. }
  34. if(arg.length == 0)
  35. {
  36. return false;
  37. }
  38. EntityPlayer p = (EntityPlayer) cs;
  39. ItemStack stack = new ItemStackBuilder(Items.SKULL, 1, 3).build();
  40. NBTTagCompound com = stack.getTagCompound();
  41. if(com == null)
  42. {
  43. this.getModule().send(cs, GlobalText.shouldNotHappen());
  44. return true;
  45. }
  46. GameProfile gameprofile = KajetansMod.playerbank.getDataBank().getOfflinePlayer(arg[0]);
  47. gameprofile = TileEntitySkull.updateGameprofile(gameprofile);
  48. com.setTag("SkullOwner", NBTUtil.writeGameProfile(new NBTTagCompound(), gameprofile));
  49. Block.spawnAsEntity(p.getEntityWorld(), p.getPosition(), stack);
  50. this.getModule().send(cs, "Dir wurde ein Kopf von " + arg[0] + " gegeben.");
  51. return true;
  52. }
  53. }