Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. public class VersionHandler implements VersionInterface {
  2.    
  3.  
  4.  
  5.     public EditSession doWorldEditTask(Player player, Location location, File myfile, boolean wg) {
  6.        
  7.  
  8.         World world = player.getWorld();
  9.        
  10.         int X = location.getBlockX();
  11.         int Y = location.getBlockY();
  12.         int Z = location.getBlockZ();
  13.         location.getDirection();
  14.        
  15.         com.sk89q.worldedit.world.World AdaptedWorld = BukkitAdapter.adapt(world);
  16.        
  17.         EditSession playerEditSession = null;
  18.  
  19.         ClipboardFormat format = ClipboardFormats.findByFile(myfile);
  20.        
  21.         try (ClipboardReader reader = format.getReader(new FileInputStream(myfile))) {
  22.             Clipboard clipboard = reader.read();
  23.            
  24.             if (wg == true) {
  25.                
  26.                 String er = "h";
  27.                
  28.                 try {
  29.                 er = WorldGuardClass.wgMethod(clipboard, X, Y, Z, player, AdaptedWorld);
  30.                 } catch (NoClassDefFoundError e2){
  31.                    
  32.                 }
  33.                    
  34.    
  35.                 if (er != null) {
  36.                     try (EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(AdaptedWorld,
  37.                             -1)) {
  38.                         playerEditSession = editSession;
  39.                        
  40.                         Operation operation = new ClipboardHolder(clipboard).createPaste(editSession)
  41.                                 .to(BlockVector3.at(X, Y, Z)).ignoreAirBlocks(true).build();
  42.                        
  43.                         try {
  44.                             Operations.complete(operation);
  45.                             editSession.flushSession();
  46.                         } catch (WorldEditException e) {
  47.                             player.sendMessage(ChatColor.RED + "OOPS! Something went wrong, please contact an administrator");
  48.                             e.printStackTrace();
  49.                         }
  50.                     }
  51.                     return playerEditSession;
  52.                    
  53.                 } else {
  54.                     return null;
  55.                 }
  56.             }
  57.            
  58.            
  59.            
  60.            
  61.         } catch (FileNotFoundException e) {
  62.             e.printStackTrace();
  63.             player.sendMessage(ChatColor.RED + "This file was not found! Contact an administrator");
  64.             System.out.println("StructurePasteCommand > " + "FileNotFoundException: ");
  65.             System.out.println("StructurePasteCommand > " + "Ensure schematic has extension in the file .schem or .schematic (not supported)");
  66.             System.out.println("StructurePasteCommand > " + "NOTE: .schem files are not the same as .schematic files! ");
  67.             System.out.println("StructurePasteCommand > " + "If you're having issues that you feel to be unresolveable, contact the author. ");
  68.        
  69.         } catch (IOException e) {
  70.             e.printStackTrace();
  71.         }
  72.        
  73.        
  74.        
  75.         return playerEditSession;
  76.        
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement