Advertisement
Guest User

Untitled

a guest
May 10th, 2015
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.65 KB | None | 0 0
  1. package AutoSchematic;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.logging.Logger;
  7.  
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.Difficulty;
  11. import org.bukkit.Location;
  12. import org.bukkit.Material;
  13. import org.bukkit.World;
  14. import org.bukkit.block.Block;
  15. import org.bukkit.command.Command;
  16. import org.bukkit.command.CommandSender;
  17. import org.bukkit.configuration.ConfigurationSection;
  18. import org.bukkit.configuration.file.FileConfiguration;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.event.EventHandler;
  21. import org.bukkit.event.EventPriority;
  22. import org.bukkit.event.Listener;
  23. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
  24. import org.bukkit.event.player.PlayerJoinEvent;
  25. import org.bukkit.event.player.PlayerTeleportEvent;
  26. import org.bukkit.plugin.PluginDescriptionFile;
  27. import org.bukkit.plugin.PluginManager;
  28. import org.bukkit.plugin.java.JavaPlugin;
  29.  
  30. import com.sk89q.worldedit.CuboidClipboard;
  31. import com.sk89q.worldedit.EditSession;
  32. import com.sk89q.worldedit.MaxChangedBlocksException;
  33. import com.sk89q.worldedit.Vector;
  34. import com.sk89q.worldedit.bukkit.BukkitWorld;
  35. import com.sk89q.worldedit.data.DataException;
  36.  
  37. public class Main extends JavaPlugin implements Listener{
  38.    
  39.     public static final Logger logger = Logger.getLogger("Minecraft");
  40.    
  41.     @Override
  42.     public void onDisable(){
  43.         PluginDescriptionFile pdfFile = this.getDescription();
  44.         this.logger.info(pdfFile.getName() + " Has Been DISABLED");
  45.     }
  46.  
  47.     public static ArrayList<String> reg = new ArrayList<String>();
  48.    
  49.     FileConfiguration config = null;
  50.    
  51.     @Override
  52.     public void onEnable(){
  53.         config = getConfig();
  54.         PluginDescriptionFile pdfFile  = this.getDescription();
  55.         this.logger.info(pdfFile.getName() + " Has Been ENABLED");
  56.         PluginManager pm = getServer().getPluginManager();
  57.         pm.registerEvents(this, this);
  58.        
  59.         getServer().getScheduler().scheduleSyncRepeatingTask(this,
  60.                 new Runnable() {
  61.                    
  62.                    
  63.                     @Override
  64.                     public void run() {
  65.                         {
  66.                             restoreAll();
  67.                            
  68.                         }
  69.                     }
  70.                 }, 0, 20 * 3600);
  71.     }
  72.    
  73.     public void restoreAll(){
  74.         ConfigurationSection sec = getConfig().getConfigurationSection("schematics");
  75.         for (String s : sec.getKeys(false)) {
  76.             String name = config.getString("schematics." + s + ".schematic.name");
  77.             Location loc = new Location(
  78.                     Bukkit.getWorld(config.getString("schematics." + name + ".location.World")),
  79.                             config.getDouble("schematics." + name + ".location.X"),
  80.                             config.getDouble("schematics." + name + ".location.Y"),
  81.                             config.getDouble("schematics." + name + ".location.Z"));
  82.             spawnSchematic(loc, config.getString("schematics." + s + ".schematic.name"));
  83.         }
  84.     }
  85.    
  86.    
  87.    
  88.     public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  89.         Player p = (Player) sender;
  90.         if (commandLabel.equalsIgnoreCase("restoreAll")){
  91.             p.sendMessage("Restoring!");
  92.             restoreAll();
  93.             p.sendMessage("Restored!");
  94.         }else{
  95.         if (args.length < 2 || args.length < 2){
  96.             sender.sendMessage("Usage: /pasteSchematic <SchematicName> <DelayToPaste>");
  97.             return true;
  98.         }
  99.         Location loc = p.getLocation();
  100.         config.set("schematics."+ args[0] + ".location.World" , loc.getWorld().getName());
  101.         config.set("schematics."+ args[0] + ".location.X" , loc.getX());
  102.         config.set("schematics."+ args[0] + ".location.Y" , loc.getY());
  103.         config.set("schematics."+ args[0] + ".location.Z" , loc.getZ());
  104.         config.set("schematics."+ args[0] + ".schematic.name" , args[0]);
  105.         config.set("schematics."+ args[0] + ".schematic.delay" , args[1]);
  106.         saveConfig();
  107.         }
  108.         return true;
  109.     }
  110.     public static ArrayList<String> madeHouse = new ArrayList<String>();
  111.    
  112.     public void spawnSchematic(Location loc, String name){
  113.        
  114.         int yloc = 1;
  115.         if (!loc.getChunk().isLoaded()){
  116.             loc.getChunk().load();
  117.         }
  118.        
  119.         World world = loc.getWorld();
  120.         Vector vec = new Vector(loc.getX(), loc.getY(), loc.getZ());
  121.        
  122.         try {
  123.             loadArea(world, new File("plugins/WorldEdit/schematics/" + name + ".schematic"), vec);
  124.             //loadArea(world, new File("C:/CraftBukkit/Server/plugins/WorldEdit/schematics/house.schematic"), vec);
  125.         } catch (MaxChangedBlocksException | DataException | IOException e) {
  126.             // TODO Auto-generated catch block
  127.             e.printStackTrace();
  128.         }
  129.        
  130.     }
  131.    
  132.    
  133.     public void loadArea(World world, File file, Vector origin) throws DataException, IOException, MaxChangedBlocksException {
  134.     EditSession es = new EditSession(new BukkitWorld(world), 999999999);
  135.     CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
  136.     cc.paste(es, origin, false);
  137.     //Bukkit.getServer().broadcastMessage("Done1!");
  138.     }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement