WorldCommands.java 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package me.km.snuviscript.commands;
  2. import java.util.ArrayList;
  3. import java.util.stream.Collectors;
  4. import me.hammerle.snuviscript.code.ScriptManager;
  5. import me.km.utils.Location;
  6. import me.km.utils.Utils;
  7. import net.minecraft.server.MinecraftServer;
  8. import net.minecraft.util.math.BlockPos;
  9. import net.minecraft.world.Difficulty;
  10. import net.minecraft.world.World;
  11. import net.minecraft.world.server.ServerWorld;
  12. public class WorldCommands {
  13. @SuppressWarnings("")
  14. public static void registerFunctions(ScriptManager sm, MinecraftServer server) {
  15. sm.registerAlias("players.toworldlist", "world.getplayers");
  16. sm.registerFunction("world.get", (sc, in) -> Utils.getWorldFromName(server, in[0].getString(sc)));
  17. sm.registerFunction("world.getname", (sc, in) -> Utils.getWorldName((World) in[0].get(sc)));
  18. sm.registerConsumer("world.setdiffi", (sc, in) -> {
  19. server.setDifficultyForAllWorlds(Difficulty.valueOf(in[1].getString(sc).toUpperCase()), true);
  20. });
  21. sm.registerConsumer("world.setspawn", (sc, in) -> {
  22. Location l = ((Location) in[0].get(sc));
  23. ((ServerWorld) l.getWorld()).func_241124_a__(l.getBlockPos(), in.length > 0 ? in[1].getFloat(sc) : 0.0f);
  24. });
  25. sm.registerFunction("world.getspawn", (sc, in) -> {
  26. ServerWorld w = (ServerWorld) in[0].get(sc);
  27. BlockPos pos = w.getSpawnPoint();
  28. return new Location(w, pos.getX(), pos.getY(), pos.getZ(), 0.0f, 0.0f);
  29. });
  30. sm.registerFunction("world.getall", (sc, in) -> {
  31. ArrayList<World> worlds = new ArrayList<>();
  32. for(World w : server.getWorlds()) {
  33. worlds.add(w);
  34. }
  35. return worlds;
  36. });
  37. sm.registerConsumer("world.settime", (sc, in) -> ((ServerWorld) in[0].get(sc)).setDayTime(in[1].getLong(sc)));
  38. sm.registerFunction("world.gettime", (sc, in) -> (double) ((World) in[0].get(sc)).getDayTime());
  39. sm.registerFunction("world.hasstorm", (sc, in) -> ((World) in[0].get(sc)).isRaining());
  40. sm.registerConsumer("world.clearweather", (sc, in) -> {
  41. ((ServerWorld) in[0].get(sc)).func_241113_a_(in[1].getInt(sc), 0, false, false);
  42. });
  43. sm.registerConsumer("world.setrain", (sc, in) -> {
  44. ((ServerWorld) in[0].get(sc)).getWorld().func_241113_a_(0, in[1].getInt(sc), true, false);
  45. });
  46. sm.registerConsumer("world.setthunder", (sc, in) -> {
  47. ((ServerWorld) in[0].get(sc)).getWorld().func_241113_a_(0, in[1].getInt(sc), true, true);
  48. });
  49. sm.registerFunction("world.getentities", (sc, in) -> {
  50. return ((ServerWorld) in[0].get(sc)).getEntities().collect(Collectors.toList());
  51. });
  52. }
  53. }