CommandSetHome.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package me.km.commands;
  2. import me.km.api.GlobalText;
  3. import me.km.api.Location;
  4. import me.km.api.Module;
  5. import me.km.api.ModuleCommand;
  6. import me.km.api.SimpleConfig;
  7. import me.km.api.Utils;
  8. import me.km.permissions.Permissions;
  9. import net.minecraft.command.ICommandSender;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. public class CommandSetHome extends ModuleCommand
  12. {
  13. public CommandSetHome(Module m)
  14. {
  15. super("sethome", m);
  16. super.setDescription("Erstellt einen neuen Home");
  17. super.setUsage("/sethome <name>");
  18. super.setPermission(Permissions.SET_HOME);
  19. }
  20. public boolean addHome(String name, String uuid, Location l)
  21. {
  22. SimpleConfig sc = new SimpleConfig(this.getModule(), "home/" + uuid + "/" + name, false);
  23. if(sc.exists())
  24. {
  25. return false;
  26. }
  27. sc.setLocation("home", l);
  28. sc.save();
  29. return true;
  30. }
  31. @Override
  32. public boolean execute(ICommandSender cs, String[] arg)
  33. {
  34. if(!(cs instanceof EntityPlayer))
  35. {
  36. this.getModule().send(cs, GlobalText.onlyPlayer());
  37. return true;
  38. }
  39. if(arg.length < 1)
  40. {
  41. return false;
  42. }
  43. EntityPlayer p = ((EntityPlayer) cs);
  44. if(addHome(arg[0], p.getUniqueID().toString(), Utils.getEntityLocation(p)))
  45. {
  46. this.getModule().send(cs, "Der Home " + arg[0] + " wurde erstellt.");
  47. return true;
  48. }
  49. this.getModule().send(cs, "Der Home " + arg[0] + " existiert bereits.");
  50. return true;
  51. }
  52. }