Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. package _112.saveclaims;
  2.  
  3. import com.boydti.fawe.object.schematic.Schematic;
  4. import com.boydti.fawe.util.EditSessionBuilder;
  5. import com.boydti.fawe.util.TaskManager;
  6. import com.sk89q.worldedit.EditSession;
  7. import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
  8. import com.sk89q.worldedit.math.BlockVector3;
  9. import com.sk89q.worldedit.regions.CuboidRegion;
  10. import me.ryanhamshire.GriefPrevention.Claim;
  11. import me.ryanhamshire.GriefPrevention.GriefPrevention;
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.Location;
  14. import org.bukkit.World;
  15. import org.bukkit.command.Command;
  16. import org.bukkit.command.CommandExecutor;
  17. import org.bukkit.command.CommandSender;
  18. import org.bukkit.entity.Player;
  19.  
  20. public class Save implements CommandExecutor {
  21. @Override
  22. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  23. if (sender instanceof Player) {
  24. Saveclaims sc = Saveclaims.getPlugin();
  25. Player player = (Player) sender;
  26. if (args.length == 2 && args[0] != null && args[1] != null) {
  27. if (player.getServer().getWorld(args[0]) != null && player.getServer().getWorld(args[1]) != null) {
  28. World world1;
  29. World world2;
  30. world1 = Bukkit.getWorld(args[0]);
  31. world2 = Bukkit.getWorld(args[1]);
  32.  
  33. EditSession copyWorld = new EditSessionBuilder(world1.getName())
  34. .allowedRegionsEverywhere()
  35. .build();
  36. EditSession pasteWorld = new EditSessionBuilder(world2.getName())
  37. .allowedRegionsEverywhere()
  38. .fastmode(true)
  39. .build();
  40.  
  41. TaskManager.IMP.async(() -> {
  42. Location corner1;
  43. Location corner2;
  44.  
  45. int claims = GriefPrevention.instance.dataStore.getClaims().size();
  46. int done = 0;
  47.  
  48. for (Claim claim : GriefPrevention.instance.dataStore.getClaims()) {
  49. corner1 = claim.getLesserBoundaryCorner();
  50. corner2 = claim.getGreaterBoundaryCorner();
  51. world2.getChunkAtAsync(corner1.getBlockZ(), corner2.getBlockZ());
  52.  
  53. if (!corner1.getWorld().getName().equals(args[0])) {
  54. Saveclaims.getPlugin().logMessage((String.format("Skipping claim in %s doesn't match specified world %s", corner1.getWorld().getName(), world1.getName())));
  55. continue;
  56. }
  57.  
  58. Saveclaims.getPlugin().logMessage(String.format("Copying claim %s:%s from %s %s %s", claim.getOwnerName(), claim.getID(), corner1.getBlockX(), corner1.getBlockY(), corner1.getBlockZ()));
  59.  
  60.  
  61. BlockVector3 pos1 = BlockVector3.at(corner1.getX(), 0,corner1.getZ());
  62. BlockVector3 pos2 = BlockVector3.at(corner2.getX(), world2.getMaxHeight(),corner2.getZ());
  63.  
  64. CuboidRegion copyRegion = new CuboidRegion(pos1, pos2);
  65. BlockArrayClipboard lazyCopy = copyWorld.lazyCopy(copyRegion);
  66.  
  67. Schematic schem = new Schematic(lazyCopy);
  68. BlockVector3 to = BlockVector3.at(corner1.getBlockX(), 0, corner1.getBlockZ());
  69. schem.paste(pasteWorld, to, true);
  70.  
  71. pasteWorld.flushQueue();
  72. pasteWorld.fixLighting(copyRegion.getChunks());
  73. world2.unloadChunk(corner1.getBlockZ(), corner2.getBlockZ());
  74.  
  75. Saveclaims.getPlugin().logMessage(String.format("Copied claim %s", claim.getID()));
  76. claims--;
  77. done++;
  78. if (done == 10) {
  79. done = 0;
  80. Saveclaims.getPlugin().logMessage(String.format("%s claims left to copy", claims));
  81.  
  82. }
  83.  
  84. }
  85. });
  86.  
  87. } else {
  88. sc.sendMessage(sender, "A world you specified doesn't exist");
  89. return true;
  90. }
  91. } else {
  92. sc.sendMessage(sender, "Please specify two worlds /saveclaims <world1> <world2>");
  93. return true;
  94. }
  95.  
  96. }
  97. return true;
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement