PlotCommands.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package me.km.snuviscript.commands;
  2. import me.hammerle.snuviscript.code.ScriptManager;
  3. import me.km.overrides.ModEntityPlayerMP;
  4. import me.km.plots.PlotMap;
  5. import me.km.plots.WorldPlotMap;
  6. import me.km.utils.Location;
  7. import net.minecraft.world.World;
  8. public class PlotCommands {
  9. public static void registerFunctions(ScriptManager sm, WorldPlotMap plots) {
  10. sm.registerFunction("plot.get", (sc, in) -> {
  11. Location l = (Location) in[0].get(sc);
  12. return plots.getPlots(l.getWorld(), l.getBlockPos());
  13. });
  14. sm.registerFunction("plot.check", (sc, in) -> {
  15. Location l = (Location) in[0].get(sc);
  16. ModEntityPlayerMP p = (ModEntityPlayerMP) in[1].get(sc);
  17. int flags = in[2].getInt(sc);
  18. boolean empty = in[3].getBoolean(sc);
  19. return plots.canDoSomething(l.getWorld(), l.getBlockPos(), p, flags, empty);
  20. });
  21. sm.registerConsumer("plot.setflags", (sc, in) -> {
  22. PlotMap.Plot p = (PlotMap.Plot) in[0].get(sc);
  23. p.setFlag(in[1].getInt(sc), in[2].getBoolean(sc));
  24. });
  25. sm.registerFunction("plot.hasflags",
  26. (sc, in) -> ((PlotMap.Plot) in[0].get(sc)).hasFlags(in[1].getInt(sc)));
  27. sm.registerFunction("plot.getflags",
  28. (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getFlags());
  29. sm.registerFunction("plot.getowners",
  30. (sc, in) -> ((PlotMap.Plot) in[0].get(sc)).getOwners());
  31. sm.registerFunction("plot.add", (sc, in) -> {
  32. Location l1 = (Location) in[0].get(sc);
  33. Location l2 = (Location) in[1].get(sc);
  34. if(l1.getWorld() != l2.getWorld()) {
  35. throw new IllegalArgumentException("worlds not equal for locations");
  36. }
  37. if(in.length > 2) {
  38. return plots.add(l1.getWorld(), l1.getBlockPos(), l2.getBlockPos(),
  39. in[2].getInt(sc));
  40. }
  41. return plots.add(l1.getWorld(), l1.getBlockPos(), l2.getBlockPos());
  42. });
  43. sm.registerConsumer("plot.remove", (sc, in) -> {
  44. plots.remove((World) in[1].get(sc), (PlotMap.Plot) in[0].get(sc));
  45. });
  46. sm.registerFunction("plot.getname", (sc, in) -> ((PlotMap.Plot) in[0].get(sc)).getName());
  47. sm.registerConsumer("plot.setname", (sc, in) -> {
  48. ((PlotMap.Plot) in[0].get(sc)).setName(in[1].getString(sc));
  49. });
  50. sm.registerFunction("plot.getid",
  51. (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getId());
  52. sm.registerFunction("plot.iterator", (sc, in) -> {
  53. World word = (World) in[0].get(sc);
  54. if(in.length >= 2) {
  55. return plots.getIterator(word, CommandUtils.getUUID(in[1].get(sc)));
  56. }
  57. return plots.getIterator(word);
  58. });
  59. sm.registerFunction("plot.intersecting",
  60. (sc, in) -> plots.getIntersectingPlots((World) in[0].get(sc), in[1].getInt(sc),
  61. in[2].getInt(sc), in[3].getInt(sc), in[4].getInt(sc), in[5].getInt(sc),
  62. in[6].getInt(sc)));
  63. sm.registerFunction("plot.getminx",
  64. (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMinX());
  65. sm.registerFunction("plot.getminy",
  66. (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMinY());
  67. sm.registerFunction("plot.getminz",
  68. (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMinZ());
  69. sm.registerFunction("plot.getmaxx",
  70. (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMaxX());
  71. sm.registerFunction("plot.getmaxy",
  72. (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMaxY());
  73. sm.registerFunction("plot.getmaxz",
  74. (sc, in) -> (double) ((PlotMap.Plot) in[0].get(sc)).getMaxZ());
  75. }
  76. }