CommandSign.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package me.km.commands;
  2. import me.km.api.Utils;
  3. import me.km.api.GlobalText;
  4. import me.km.api.Module;
  5. import me.km.api.ModuleCommand;
  6. import me.km.chatmanager.ChatManager;
  7. import me.km.permissions.Permissions;
  8. import me.km.utils.SpecialBlockUtils;
  9. import net.minecraft.block.Block;
  10. import net.minecraft.command.ICommandSender;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.init.Blocks;
  13. import net.minecraft.tileentity.TileEntitySign;
  14. import net.minecraft.util.math.BlockPos;
  15. import net.minecraft.world.World;
  16. public class CommandSign extends ModuleCommand
  17. {
  18. public CommandSign(Module m)
  19. {
  20. super("sign", m);
  21. super.setDescription("Editiert ein Schild");
  22. super.setUsage("/sign <1-4> [text]");
  23. super.setPermission(Permissions.SIGN);
  24. }
  25. @Override
  26. public boolean execute(ICommandSender cs, String[] arg)
  27. {
  28. if(!(cs instanceof EntityPlayer))
  29. {
  30. this.getModule().send(cs, GlobalText.onlyPlayer());
  31. return true;
  32. }
  33. if(arg.length < 1)
  34. {
  35. return false;
  36. }
  37. EntityPlayer p = (EntityPlayer) cs;
  38. World w = p.getEntityWorld();
  39. BlockPos pos = Utils.getPlayerTarget(p, 20, true);
  40. Block b = w.getBlockState(pos).getBlock();
  41. if(b == Blocks.STANDING_SIGN || b == Blocks.WALL_SIGN)
  42. {
  43. TileEntitySign sign = (TileEntitySign) w.getTileEntity(pos);
  44. if(sign == null)
  45. {
  46. this.getModule().send(cs, GlobalText.shouldNotHappen());
  47. return true;
  48. }
  49. int line;
  50. try
  51. {
  52. line = Integer.parseInt(arg[0]) - 1;
  53. if(line > 3 || line < 0)
  54. {
  55. throw new java.lang.NumberFormatException();
  56. }
  57. }
  58. catch(java.lang.NumberFormatException ex)
  59. {
  60. this.getModule().send(cs, "Du musst eine Zahl von 1 bis 4 eingeben.");
  61. return true;
  62. }
  63. String newText = Utils.connectSpaces(arg, 1);
  64. newText = ChatManager.colorMessage(newText, p);
  65. SpecialBlockUtils.setSignLine(sign, line, newText);
  66. return true;
  67. }
  68. this.getModule().send(cs, "Du bist nicht auf ein Schild gerichtet.");
  69. return true;
  70. }
  71. }