Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package AutoSchematic;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.logging.Logger;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Difficulty;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerCommandPreprocessEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import org.bukkit.event.player.PlayerTeleportEvent;
- import org.bukkit.plugin.PluginDescriptionFile;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import com.sk89q.worldedit.CuboidClipboard;
- import com.sk89q.worldedit.EditSession;
- import com.sk89q.worldedit.MaxChangedBlocksException;
- import com.sk89q.worldedit.Vector;
- import com.sk89q.worldedit.bukkit.BukkitWorld;
- import com.sk89q.worldedit.data.DataException;
- public class Main extends JavaPlugin implements Listener{
- public static final Logger logger = Logger.getLogger("Minecraft");
- @Override
- public void onDisable(){
- PluginDescriptionFile pdfFile = this.getDescription();
- this.logger.info(pdfFile.getName() + " Has Been DISABLED");
- }
- public static ArrayList<String> reg = new ArrayList<String>();
- FileConfiguration config = null;
- @Override
- public void onEnable(){
- config = getConfig();
- PluginDescriptionFile pdfFile = this.getDescription();
- this.logger.info(pdfFile.getName() + " Has Been ENABLED");
- PluginManager pm = getServer().getPluginManager();
- pm.registerEvents(this, this);
- getServer().getScheduler().scheduleSyncRepeatingTask(this,
- new Runnable() {
- @Override
- public void run() {
- {
- restoreAll();
- }
- }
- }, 0, 20 * 3600);
- }
- public void restoreAll(){
- ConfigurationSection sec = getConfig().getConfigurationSection("schematics");
- for (String s : sec.getKeys(false)) {
- String name = config.getString("schematics." + s + ".schematic.name");
- Location loc = new Location(
- Bukkit.getWorld(config.getString("schematics." + name + ".location.World")),
- config.getDouble("schematics." + name + ".location.X"),
- config.getDouble("schematics." + name + ".location.Y"),
- config.getDouble("schematics." + name + ".location.Z"));
- spawnSchematic(loc, config.getString("schematics." + s + ".schematic.name"));
- }
- }
- public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
- Player p = (Player) sender;
- if (commandLabel.equalsIgnoreCase("restoreAll")){
- p.sendMessage("Restoring!");
- restoreAll();
- p.sendMessage("Restored!");
- }else{
- if (args.length < 2 || args.length < 2){
- sender.sendMessage("Usage: /pasteSchematic <SchematicName> <DelayToPaste>");
- return true;
- }
- Location loc = p.getLocation();
- config.set("schematics."+ args[0] + ".location.World" , loc.getWorld().getName());
- config.set("schematics."+ args[0] + ".location.X" , loc.getX());
- config.set("schematics."+ args[0] + ".location.Y" , loc.getY());
- config.set("schematics."+ args[0] + ".location.Z" , loc.getZ());
- config.set("schematics."+ args[0] + ".schematic.name" , args[0]);
- config.set("schematics."+ args[0] + ".schematic.delay" , args[1]);
- saveConfig();
- }
- return true;
- }
- public static ArrayList<String> madeHouse = new ArrayList<String>();
- public void spawnSchematic(Location loc, String name){
- int yloc = 1;
- if (!loc.getChunk().isLoaded()){
- loc.getChunk().load();
- }
- World world = loc.getWorld();
- Vector vec = new Vector(loc.getX(), loc.getY(), loc.getZ());
- try {
- loadArea(world, new File("plugins/WorldEdit/schematics/" + name + ".schematic"), vec);
- //loadArea(world, new File("C:/CraftBukkit/Server/plugins/WorldEdit/schematics/house.schematic"), vec);
- } catch (MaxChangedBlocksException | DataException | IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public void loadArea(World world, File file, Vector origin) throws DataException, IOException, MaxChangedBlocksException {
- EditSession es = new EditSession(new BukkitWorld(world), 999999999);
- CuboidClipboard cc = CuboidClipboard.loadSchematic(file);
- cc.paste(es, origin, false);
- //Bukkit.getServer().broadcastMessage("Done1!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement