/WG2OvR/regions5.js.php

https://github.com/cnlpete/Minecraft-Overviewer-Addons · PHP · 132 lines · 97 code · 20 blank · 15 comment · 20 complexity · 2b4f734e75170e67d6e94419b17c71b2 MD5 · raw file

  1. <?php
  2. // OPTIONS HERE.... ooooOooo so many options it's overwhelming, how are you ever going to get through all of these!?
  3. $yml = @'<serverdir>\plugins\WorldGuard\worlds\<worldname>\regions.yml';
  4. $color_chestdeny = "#880000"; // what color should the region be when the flag chestaccess-deny is found?
  5. $color_normal = "#FFAA00"; // what color should normal regions be colored as?
  6. $debug = false; // will break overviewer, but show the contents of the arrays... debuging only.
  7. //Dragons below! Don't change below unless your name is Michael Writhe... :)
  8. $output = "// Exported from WorldGuard v5x Regions file\n";
  9. $output .= "// Coded by Michael Writhe - michael[at]writhem[dot]com\n";
  10. $output .= "// http://goo.gl/dc0tV\n";
  11. $output .= "overviewer.collections.regionDatas.push([\n";
  12. require_once "spyc.php"; // YAML Library.
  13. $data = spyc_load_file($yml);
  14. $lines = file($yml);
  15. foreach ($data["regions"] as $label => $region) {
  16. if ($region["type"] == "cuboid") {
  17. //cube.
  18. $color = $color_normal;
  19. if(isset($region["flags"]["chest-access"])) {
  20. if ($region["flags"]["chest-access"] == "deny") {
  21. $color = $color_chestdeny; // no chest access = red
  22. }
  23. }
  24. $minx = $region["min"]["x"];
  25. $miny = $region["min"]["y"];
  26. $minz = $region["min"]["z"];
  27. $maxx = $region["max"]["x"];
  28. $maxy = $region["max"]["y"];
  29. $maxz = $region["max"]["z"];
  30. //determine if drawing a cube is worth our time, 2 extra polygons for cube rendering.
  31. // if the bottom is more than 3m lower than the top, cube is worth it.
  32. $cube = false;
  33. if(abs($miny-$minx)>3) {
  34. $cube = true;
  35. }
  36. //center
  37. $output .= " //{$label}:top layer\n";
  38. $output .= " {\"label\": \"{$label}-top\", \"color\": \"{$color}\", \"opacity\": 0.5, \"closed\": true, \"path\": [\n";
  39. $output .= " {\"x\": {$minx}, \"y\": {$maxy}, \"z\": {$minz}},\n";
  40. $output .= " {\"x\": {$minx}, \"y\": {$maxy}, \"z\": {$maxz}},\n";
  41. $output .= " {\"x\": {$maxx}, \"y\": {$maxy}, \"z\": {$maxz}},\n";
  42. $output .= " {\"x\": {$maxx}, \"y\": {$maxy}, \"z\": {$minz}}\n";
  43. $output .= " ]},\n";
  44. if($cube) {
  45. //isometric cube draw
  46. $output .= " //{$label}:isometric projection-left\n";
  47. $output .= " {\"label\": \"{$label}-isoleft\", \"color\": \"{$color}\", \"opacity\": 0.5, \"closed\": true, \"path\": [\n";
  48. $output .= " {\"x\": {$minx}, \"y\": {$miny}, \"z\": {$minz}},\n";
  49. $output .= " {\"x\": {$minx}, \"y\": {$miny}, \"z\": {$maxz}},\n";
  50. $output .= " {\"x\": {$minx}, \"y\": {$maxy}, \"z\": {$maxz}},\n";
  51. $output .= " {\"x\": {$minx}, \"y\": {$maxy}, \"z\": {$minz}}\n";
  52. $output .= " ]},\n";
  53. $output .= " //{$label}:isometric projection-right\n";
  54. $output .= " {\"label\": \"{$label}-isoright\", \"color\": \"{$color}\", \"opacity\": 0.5, \"closed\": true, \"path\": [\n";
  55. $output .= " {\"x\": {$maxx}, \"y\": {$maxy}, \"z\": {$maxz}},\n";
  56. $output .= " {\"x\": {$minx}, \"y\": {$maxy}, \"z\": {$maxz}},\n";
  57. $output .= " {\"x\": {$minx}, \"y\": {$miny}, \"z\": {$maxz}},\n";
  58. $output .= " {\"x\": {$maxx}, \"y\": {$miny}, \"z\": {$maxz}}\n";
  59. $output .= " ]},\n";
  60. }
  61. if($debug) { print($name);print_r($region); }
  62. } elseif($region["type"] == "polygon") {
  63. //polygon.
  64. $color = $color_normal;
  65. if(isset($region["flags"]["chest-access"])) {
  66. if ($region["flags"]["chest-access"] == "deny") {
  67. $color = $color_chestdeny; // no chest access = red
  68. }
  69. }
  70. // whats the virtical limits? easy for polygons ... holy dina!
  71. $miny = $region["min-y"];
  72. $maxy = $region["max-y"];
  73. //determine if drawing a cube is worth our time, 2 extra polygons for cube rendering.
  74. // if the bottom is more than 3m lower than the top, cube is worth it.
  75. $cube = false;
  76. if(($maxy-$miny)>3) {
  77. $cube = true;
  78. } else {
  79. $maxy = round(($maxy+$miny)/2,0);
  80. }
  81. //extract the points from the yml data in order to work with them easier later.
  82. $points = array("x"=>array(),"z"=>array());
  83. for ($n = 0;$n <= count($region);$n++) {
  84. if (isset($region[$n]["x"]) && isset($region[$n]["z"])) {
  85. array_push($points["x"],$region[$n]["x"]);
  86. array_push($points["z"],$region[$n]["z"]);
  87. }
  88. }
  89. // generate the top layer
  90. $output .= " //{$label}:top layer\n";
  91. $output .= " {\"label\": \"{$label}-top\", \"color\": \"{$color}\", \"opacity\": 0.5, \"closed\": true, \"path\": [\n";
  92. for ($n = 0;$n < count($points["x"]);$n++) {
  93. $output .= " {\"x\": {$points["x"][$n]}, \"y\": {$maxy}, \"z\": {$points["z"][$n]}},\n";
  94. }
  95. //same operation for every line, but last line has to be different, strip the ,\n at the end of it.
  96. $output = substr($output,0,-2);
  97. $output .= "\n ]},\n";
  98. if ($cube) {
  99. //isometric cube draw
  100. $output .= " //{$label}:isometric projection-left\n";
  101. $output .= " {\"label\": \"{$label}-isoleft\", \"color\": \"{$color}\", \"opacity\": 0.5, \"closed\": true, \"path\": [\n";
  102. for ($n = 0;$n < count($points["x"]);$n++) {
  103. $output .= " {\"x\": {$points["x"][$n]}, \"y\": {$miny}, \"z\": {$points["z"][$n]}},\n";
  104. }
  105. $output = substr($output,0,-2);
  106. $output .= "\n ]},\n";
  107. }
  108. }
  109. }
  110. $output .= "]);";
  111. print $output;
  112. ?>