noftaly

Untitled

Jul 31st, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. import:
  2. java.awt.Color
  3. java.awt.Image
  4. java.awt.image.BufferedImage
  5.  
  6. java.util.HashMap
  7. java.util.Map
  8. java.lang.Integer
  9. java.net.URL
  10. javax.imageio.ImageIO
  11.  
  12. org.bukkit.ChatColor
  13. org.bukkit.DyeColor
  14.  
  15. ch.njol.skript.Skript
  16. ch.njol.skript.variables.Variables
  17. ch.njol.skript.lang.Variable
  18.  
  19. com.google.common.collect.Maps
  20.  
  21. on script load:
  22. set {image::colorsMap} to new HashMap()
  23. {image::colorsMap}.put(ChatColor.DARK_BLUE, new Color(0, 0, 170/255))
  24. {image::colorsMap}.put(ChatColor.DARK_GREEN, new Color(0, 170/255, 0))
  25. {image::colorsMap}.put(ChatColor.DARK_AQUA, new Color(0, 170/255, 170/255))
  26. {image::colorsMap}.put(ChatColor.DARK_RED, new Color(170/255, 0, 0))
  27. {image::colorsMap}.put(ChatColor.DARK_PURPLE, new Color(170/255, 0, 170/255))
  28. {image::colorsMap}.put(ChatColor.GOLD, new Color(1, 170/255, 0))
  29. {image::colorsMap}.put(ChatColor.BLUE, new Color(85/255, 85/255, 1))
  30. {image::colorsMap}.put(ChatColor.GREEN, new Color(85/255, 1, 85/255))
  31. {image::colorsMap}.put(ChatColor.AQUA, new Color(85/255, 1, 1))
  32. {image::colorsMap}.put(ChatColor.RED, new Color(1, 85/255, 85/255))
  33. {image::colorsMap}.put(ChatColor.LIGHT_PURPLE, new Color(1, 85/255, 1))
  34. {image::colorsMap}.put(ChatColor.YELLOW, new Color(1, 1, 85/255))
  35.  
  36. set {image::graysMap} to new HashMap()
  37. {image::graysMap}.put(ChatColor.BLACK, new Color(0, 0, 0))
  38. {image::graysMap}.put(ChatColor.DARK_GRAY, new Color(85/255, 85/255, 85/255))
  39. {image::graysMap}.put(ChatColor.GRAY, new Color(170/255, 170/255, 170/255))
  40. {image::graysMap}.put(ChatColor.WHITE, new Color(1, 1, 1))
  41.  
  42. function getDistance(c1: object, c2: object) :: number:
  43. set {_c1.red} to {_c1}.getRed()
  44. set {_c1.green} to {_c1}.getGreen()
  45. set {_c1.blue} to {_c1}.getBlue()
  46. set {_c2.red} to {_c2}.getRed()
  47. set {_c2.green} to {_c2}.getGreen()
  48. set {_c2.blue} to {_c2}.getBlue()
  49. set {_rmean} to ({_c1.red} + {_c2.red}) / 2.0
  50. set {_r} to {_c1.red} - {_c2.red}
  51. set {_g} to {_c1.green} - {_c2.green}
  52. set {_b} to {_c1.blue} - {_c2.blue}
  53. set {_weightR} to 2 + {_rmean} / 256
  54. set {_weightG} to 4
  55. set {_weightB} to 2 + (255 - {_rmean}) / 256
  56. return {_weightR} * {_r} * {_r} + {_weightG} * {_g} * {_g} + {_weightB} * {_b} * {_b}
  57.  
  58. function areIdentical(c1: object, c2: object) :: boolean:
  59. set {_c1.red} to {_c1}.getRed()
  60. set {_c1.green} to {_c1}.getGreen()
  61. set {_c1.blue} to {_c1}.getBlue()
  62. set {_c2.red} to {_c2}.getRed()
  63. set {_c2.green} to {_c2}.getGreen()
  64. set {_c2.blue} to {_c2}.getBlue()
  65. if abs({_c1.red} - {_c2.red}) <= 5:
  66. if abs({_c1.green} - {_c2.green}) <= 5:
  67. if abs({_c1.blue} - {_c2.blue}) <= 5:
  68. return true
  69. return false
  70.  
  71. function getClosestChatColor(c: object) :: integer:
  72. if {_c}.getAlpha() < 80:
  73. broadcast "DEBUG 1"
  74. return ChatColor.WHITE
  75.  
  76. broadcast "DEBUG 2"
  77. set {_v::*} to ...{image::colorsMap}.entrySet() # convertit en liste Skript
  78. loop {_v::*}:
  79. broadcast "DEBUG 3 (%loop-value% | %loop-value.getValue()% | %areIdentical(loop-value.getValue(), {_c})%)"
  80. if (areIdentical(loop-value.getValue(), {_c})):
  81. return loop-value.getKey()
  82.  
  83. set {_bestGrayDistance} to 100000000
  84. set {_bestGrayMatch} to null
  85. broadcast "DEBUG 4"
  86.  
  87. set {_v::*} to ...{image::graysMap}.entrySet() # convertit en liste Skript
  88. loop {_v::*}:
  89. set {_distance} to getDistance({_c}, loop-value.getValue())
  90. broadcast "DEBUG 5 (%loop-value% | %loop-value.getValue()% | %{_distance}%)"
  91. if {_distance} < {_bestGrayDistance}:
  92. broadcast "DEBUG 6 (best gray)"
  93. set {_bestGrayDistance} to {_distance}
  94. set {_bestGrayMatch} to loop-value.getKey()
  95.  
  96. if {_bestGrayDistance} < 17500:
  97. return {_bestGrayMatch}
  98. broadcast "DEBUG 7 (%{_bestGrayMatch}%)"
  99.  
  100. set {_bestColorDistance} to 100000000
  101. set {_bestColorMatch} to null
  102.  
  103. set {_v::*} to ...{image::colorsMap}.entrySet() # convertit en liste Skript
  104. loop {_v::*}:
  105. set {_distance} to getDistance({_c}, loop-value.getValue())
  106. broadcast "DEBUG 8 (%loop-value% | %loop-value.getValue()% | %{_distance}%)"
  107. if {_distance} < {_bestColorDistance}:
  108. set {_bestColorDistance} to {_distance}
  109. set {_bestColorMatch} to loop-value.getKey()
  110.  
  111. broadcast "DEBUG 9 %{_bestColorMatch}%"
  112. # Minecraft has 15 colors
  113. return {_bestColorMatch}
  114.  
  115.  
  116. command /img [<offline player = %player%>]:
  117. trigger:
  118. get the image from url "https://cravatar.eu/helmavatar/%arg-1%/16" and save the result in {_head}
  119. loop 1 times: # ligne
  120. set {_line} to ""
  121. loop 1 times: # pixels de la ligne
  122. set {_x} to loop-value-2
  123. set {_y} to loop-value-1
  124. set {_pixelcolor} to new Color({_head}.getRGB({_x} - 1, {_y} - 1))
  125. set {_mcColor} to getClosestChatColor({_pixelcolor})
  126. set {_line} to "%{_line}%&r&%{_mcColor}%⬛"
  127. message {_line}
Advertisement
Add Comment
Please, Sign In to add comment