Guest User

Untitled

a guest
Jul 30th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1.     public void loadPhotos() {
  2.         Path path = Paths.get(main.plugin.getDataFolder().getAbsolutePath() + "/photos/");
  3.         if (!Files.exists(path))return;
  4.  
  5.         for (File file : new File(path.toString()).listFiles()) {
  6.             String FilePhotoName = file.getName();
  7.             FilePhotoName = FilePhotoName.replace(".yml", "");
  8.  
  9.             FileConfiguration photos = getPhotos(FilePhotoName);
  10.             String photokey = "photo.frames.";
  11.             ConfigurationSection photoSection = photos.getConfigurationSection(photokey);
  12.             if (photos.isConfigurationSection(photokey)) {
  13.                 for (String key : photoSection.getKeys(false)) {
  14.                     for (int i = 0; i < photoSection.getKeys(false).size(); i++) {
  15.                         if (!photos.isConfigurationSection(photokey + key + ".location")) {
  16.                             return;
  17.                         }
  18.  
  19.                         Double x = Double.valueOf(photos.getString(photokey + key + ".location.x"));
  20.                         Double y = Double.valueOf(photos.getString(photokey + key + ".location.y"));
  21.                         Double z = Double.valueOf(photos.getString(photokey + key + ".location.z"));
  22.                         World world = main.plugin.getServer().getWorld(UUID.fromString(photos.getString(photokey + key + ".world")));
  23.                         Location location = new Location(world, x, y, z);
  24.  
  25.                         MapView mapv = Bukkit.getServer().getMap(photos.getInt(photokey + key + ".mapid"));
  26.  
  27.                         for (MapRenderer render : mapv.getRenderers()) {
  28.                             mapv.removeRenderer(render);
  29.                         }
  30.  
  31.                         mapv.addRenderer(new MapRenderer() {
  32.                             @Override
  33.                             public void render(MapView map, MapCanvas canvas, Player player) {
  34.                                 try {
  35.                                     URL url = new URL(photos.getString(photokey + key + ".url"));
  36.                                     BufferedImage inputImage = ImageIO.read(url);
  37.                                     BufferedImage outputImage = new BufferedImage(128, 128, inputImage.getType());
  38.  
  39.                                     Graphics2D g2d = outputImage.createGraphics();
  40.                                     g2d.drawImage(inputImage, 0, 0, 128, 128, null);
  41.                                     g2d.dispose();
  42.  
  43.                                     canvas.drawImage(0, 0, outputImage);
  44.                                 } catch (Exception ex) {
  45.                                     ex.printStackTrace();
  46.                                 }
  47.  
  48.                             }
  49.                         });
  50.  
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment