Guest User

Untitled

a guest
Jul 8th, 2020
24
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.blocaria.hg.hg.renderers;
  2.  
  3. import com.blocaria.hg.hg.Game;
  4. import org.bukkit.Location;
  5. import org.bukkit.entity.Player;
  6. import org.bukkit.map.*;
  7.  
  8. import java.awt.*;
  9. import java.awt.image.BufferedImage;
  10.  
  11. public class AreaRenderer extends MapRenderer {
  12.  
  13. private Location endPoint;
  14. private boolean isRender;
  15. private int minX;
  16. private int deltaX;
  17. private int minZ;
  18. private int deltaZ;
  19.  
  20.  
  21. public AreaRenderer(Location endPoint) {
  22. super();
  23. this.isRender = false;
  24.  
  25. Location location1 = Game.getInstance().getCorner1();
  26. Location location2 = Game.getInstance().getCorner2();
  27. this.minX = Math.min(location1.getBlockX(), location2.getBlockX());
  28. this.deltaX = Math.max(location1.getBlockX(), location2.getBlockX()) - minX;
  29. this.minZ = Math.min(location1.getBlockZ(), location2.getBlockZ());
  30. this.deltaZ = Math.max(location1.getBlockZ(), location2.getBlockZ()) - minZ;
  31. System.out.println(minX);
  32. System.out.println(deltaX);
  33. System.out.println(minZ);
  34. System.out.println(deltaZ);
  35. this.endPoint = normalizeLoc(endPoint);
  36. }
  37.  
  38. private byte yawToDirection(double yaw) {
  39. byte direction = (byte) (Math.floor((yaw / 22.5) + 0.5) % 16);
  40. if (direction < 0) {
  41. direction += 16;
  42. }
  43. return direction;
  44. }
  45.  
  46.  
  47. private Location normalizeLoc(Location l) {
  48. int blockX = l.getBlockX() - minX;
  49. int blockZ = l.getBlockZ() - minZ;
  50. int onMapX = blockX * 256 / deltaX - 128;
  51. int onMapZ = blockZ * 256 / deltaZ - 128;
  52. return new Location(l.getWorld(), onMapX, 1, onMapZ);
  53. }
  54.  
  55. private int normalizeX(int x) {
  56. return (x - minX) * 256 / deltaX - 128;
  57. }
  58.  
  59. private int normalizeZ(int z) {
  60. return (z - minZ) * 256 / deltaZ - 128;
  61. }
  62.  
  63. @Override
  64. public void render(MapView mv, MapCanvas canvas, Player p) {
  65.  
  66. Location l = p.getLocation();
  67. int onMapX = normalizeX(l.getBlockX());
  68. int onMapZ = normalizeZ(l.getBlockZ());
  69.  
  70. MapCursor c = new MapCursor((byte) onMapX, (byte) onMapZ, yawToDirection(p.getLocation().getYaw()), MapCursor.Type.GREEN_POINTER.getValue(), true);
  71.  
  72. MapCursor x = new MapCursor((byte) endPoint.getBlockX(), (byte) endPoint.getBlockZ(), (byte) 0, MapCursor.Type.WHITE_CROSS.getValue(), true);
  73. MapCursorCollection coll = new MapCursorCollection();
  74. coll.addCursor(c);
  75. coll.addCursor(x);
  76. canvas.setCursors(coll);
  77.  
  78.  
  79.  
  80. if (isRender) {
  81. return;
  82. }
  83.  
  84. BufferedImage image = new BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB);
  85. Graphics2D g = image.createGraphics();
  86. g.setColor(new Color(68, 153, 64));
  87. g.drawString("Rejoins la safezone", 5, 10);
  88.  
  89. int diameter = 20;
  90. g.setColor(new Color(172, 163, 114));
  91. g.fillOval((endPoint.getBlockX() + 128) / 2 - diameter / 2, (endPoint.getBlockZ() + 128) / 2 - diameter / 2, diameter, diameter);
  92.  
  93. canvas.drawImage(0, 0, image);
  94. this.isRender = true;
  95. }
  96.  
  97.  
  98. }
RAW Paste Data