/Block-Hunt/Block-Hunt-master/src/NetherManiacsKingdomTeam/Block-Hunt/BlockHuntSetup.php

https://gitlab.com/Skull3x/WorkingInProgress-Plugins-Sourcecode-For-Dev · PHP · 357 lines · 339 code · 12 blank · 6 comment · 75 complexity · f472938708ccfcd7434e3c948c190084 MD5 · raw file

  1. <?php
  2. namespace NetherManiacsKingdom\Block-Hunt;
  3. use pocketmine\utils\Config;
  4. use pocketmine\level\Position;
  5. use pocketmine\item\Item;
  6. use pocketmine\item\ItemBlock;
  7. use pocketmine\Player;
  8. use pocketmine\Server;
  9. use mcg76\game\blockhunt\BlockHuntPlugIn;
  10. class BlockHuntSetup extends MiniGameBase {
  11. const SERVER_LOBBY_NAME = 1000;
  12. const SERVER_LOBBY_WORLD = 1001;
  13. const SERVER_LOBBY_POSITION = 1002;
  14. const TNTRUN_HOME_NAME = 2002;
  15. const TNTRUN_HOME_WORLD = 2041;
  16. const TNTRUN_HOME_POSITION = 2003;
  17. const TNTRUN_ARENA_NAME = 2001;
  18. const TNTRUN_ARENA_POSITION = 2010;
  19. const TNTRUN_ARENA_ENTRANCE_POSITION = 2020;
  20. const TNTRUN_ARENA_BUILDING_BOARD_BLOCKS = 2030;
  21. const TNTRUN_ARENA_BUILDING_BOARD = "ArenaBoardTypes";
  22. const CLICK_BUTTON_JOIN1_GAME = 3001;
  23. const CLICK_BUTTON_START_GAME = 3010;
  24. const CLICK_BUTTON_STOP_GAME = 3020;
  25. const CLICK_BUTTON_RESET_GAME = 3030;
  26. const CLICK_BUTTON_TOP_FLOOR_EXIT = 3040;
  27. const CLICK_BUTTON_BOTTOM_FLOOR_EXIT = 3050;
  28. const CLICK_SIGN_VIEW_GAME_STATS = 4000;
  29. const CLICK_SIGN_JOIN1_GAME = 4001;
  30. const CLICK_SIGN_JOIN2_GAME = 4011;
  31. const CLICK_SIGN_GO_HOME = 4002;
  32. const CLICK_SIGN_START_GAME = 4003;
  33. const CLICK_SIGN_GO_LOBBY = 4004;
  34. const CLICK_SIGN_RESET_GAME = 4005;
  35. public $signDiamondPos;
  36. public $signGoldPos;
  37. public $signSilverPos;
  38. public $signHiderGoldPos;
  39. public $signHiderSilverPos;
  40. public $signHiderBronsePos;
  41. public $signSeekerGoldPos;
  42. public $signSeekerSilverPos;
  43. public $signSeekerBronsePos;
  44. /**
  45. * Constructor
  46. *
  47. * @param
  48. *
  49. */
  50. public function __construct(BlockHuntPlugIn $plugin) {
  51. parent::__construct ( $plugin );
  52. $this->init ();
  53. }
  54. private function init() {
  55. }
  56. public function getMessageLanguage() {
  57. $configlang = $this->getPlugIn ()->getConfig ()->get ( "language" );
  58. if ($configlang == null) {
  59. $configlang = "EN";
  60. }
  61. return $configlang;
  62. }
  63. public function setHomeLocation(Position $pos) {
  64. $success = false;
  65. try {
  66. $config = $this->getPlugIn ()->getConfig ();
  67. $config->set ( "blockhunt_home_world", $pos->getLevel ()->getName () );
  68. $config->set ( "blockhunt_home_x", round ( $pos->x ) );
  69. $config->set ( "blockhunt_home_Y", round ( $pos->y ) );
  70. $config->set ( "blockhunt_home_z", round ( $pos->z ) );
  71. $config->save ();
  72. $success = true;
  73. } catch ( \Exception $e ) {
  74. $this->getPlugIn ()->getLogger ()->error ( $e->getMessage () );
  75. }
  76. return $success;
  77. }
  78. public function setServerLobbyLocation(Position $pos) {
  79. $success = false;
  80. try {
  81. $config = $this->getPlugIn ()->getConfig ();
  82. $config->set ( "server_lobby_world", $pos->getLevel ()->getName () );
  83. $config->set ( "server_lobby_x", round ( $pos->x ) );
  84. $config->set ( "server_lobby_y", round ( $pos->y ) );
  85. $config->set ( "server_lobby_z", round ( $pos->z ) );
  86. $config->save ();
  87. $success = true;
  88. } catch ( \Exception $e ) {
  89. $this->getPlugIn ()->getLogger ()->error ( $e->getMessage () );
  90. }
  91. return $success;
  92. }
  93. public function isSafeSpawnEnable() {
  94. $value = false;
  95. try {
  96. $config = $this->getPlugIn ()->getConfig ();
  97. $value = $config->get ( "enable_blockhunt_safespawn", false );
  98. } catch ( \Exception $e ) {
  99. $this->getPlugIn ()->getLogger ()->error ( $e->getMessage () );
  100. }
  101. return $value;
  102. }
  103. public function enablePlayerOnJoinGoToLobby() {
  104. $success = false;
  105. try {
  106. $config = $this->getPlugIn ()->getConfig ();
  107. $config->set ( "enable_spaw_lobby", "YES" );
  108. $config->save ();
  109. $success = true;
  110. } catch ( \Exception $e ) {
  111. $this->getPlugIn ()->getLogger ()->error ( $e->getMessage () );
  112. }
  113. return $success;
  114. }
  115. public function disablePlayerOnJoinGoToLobby() {
  116. $success = false;
  117. try {
  118. $config = $this->getPlugIn ()->getConfig ();
  119. $config->set ( "enable_spaw_lobby", "NO" );
  120. $config->save ();
  121. $success = true;
  122. } catch ( \Exception $e ) {
  123. $this->getPlugIn ()->getLogger ()->error ( $e->getMessage () );
  124. }
  125. return $success;
  126. }
  127. public function enableSelfReset() {
  128. $success = false;
  129. try {
  130. $config = $this->getPlugIn ()->getConfig ();
  131. $config->set ( "reset_scheduler", "YES" );
  132. $config->save ();
  133. $success = true;
  134. } catch ( \Exception $e ) {
  135. $this->getPlugIn ()->getLogger ()->error ( $e->getMessage () );
  136. }
  137. return $success;
  138. }
  139. public function disableSelfReset() {
  140. $success = false;
  141. try {
  142. $config = $this->getPlugIn ()->getConfig ();
  143. $config->set ( "reset_scheduler", "NO" );
  144. $config->save ();
  145. $success = true;
  146. } catch ( \Exception $e ) {
  147. $this->getPlugIn ()->getLogger ()->error ( $e->getMessage () );
  148. }
  149. return $success;
  150. }
  151. public function getRoundResetTime() {
  152. $resetValue = $this->getConfig ( "reset_timeout" );
  153. if ($resetValue == null) {
  154. $resetValue = 10000;
  155. }
  156. return $resetValue;
  157. }
  158. public function getRoundResetOptionContinueRunning() {
  159. $resetoption = $this->getConfig ( "reset_continue_running" );
  160. if ($resetoption == null) {
  161. $resetoption = "FULL";
  162. }
  163. return $resetoption;
  164. }
  165. public function getHomeWorldPos() {
  166. $dataX = $this->getConfig ( "blockhunt_home_x" );
  167. $dataY = $this->getConfig ( "blockhunt_home_y" );
  168. $dataZ = $this->getConfig ( "blockhunt_home_z" );
  169. if (empty ( $dataX ) || empty ( $dataY ) || empty ( $dataZ )) {
  170. return null;
  171. } else {
  172. return new Position ( $dataX, $dataY, $dataZ );
  173. }
  174. }
  175. public function getHomeWorldSignPos() {
  176. $dataX = $this->getConfig ( "blockhunt_home_sign_x" );
  177. $dataY = $this->getConfig ( "blockhunt_home_sign_y" );
  178. $dataZ = $this->getConfig ( "blockhunt_home_sign_z" );
  179. if (empty ( $dataX ) || empty ( $dataY ) || empty ( $dataZ )) {
  180. return null;
  181. } else {
  182. return new Position ( $dataX, $dataY, $dataZ );
  183. }
  184. }
  185. public function getDiamondSignPos() {
  186. if ($this->signDiamondPos === null) {
  187. $dataX = $this->getConfig ( "bh_podium_diamond_x" );
  188. $dataY = $this->getConfig ( "bh_podium_diamond_y" );
  189. $dataZ = $this->getConfig ( "bh_podium_diamond_z" );
  190. if (empty ( $dataX ) || empty ( $dataY ) || empty ( $dataZ )) {
  191. return null;
  192. } else {
  193. $this->signDiamondPos = new Position ( $dataX, $dataY, $dataZ );
  194. }
  195. }
  196. return $this->signDiamondPos;
  197. }
  198. public function getSilverSignPos() {
  199. if ($this->signSilverPos === null) {
  200. $dataX = $this->getConfig ( "bh_podium_silver_x" );
  201. $dataY = $this->getConfig ( "bh_podium_silver_y" );
  202. $dataZ = $this->getConfig ( "bh_podium_silver_z" );
  203. if (empty ( $dataX ) || empty ( $dataY ) || empty ( $dataZ )) {
  204. return null;
  205. } else {
  206. $this->signSilverPos = new Position ( $dataX, $dataY, $dataZ );
  207. }
  208. }
  209. return $this->signSilverPos;
  210. }
  211. public function getGoldSignPos() {
  212. if ($this->signGoldPos === null) {
  213. $dataX = $this->getConfig ( "bh_podium_gold_x" );
  214. $dataY = $this->getConfig ( "bh_podium_gold_y" );
  215. $dataZ = $this->getConfig ( "bh_podium_gold_z" );
  216. if (empty ( $dataX ) || empty ( $dataY ) || empty ( $dataZ )) {
  217. return null;
  218. } else {
  219. $this->signGoldPos = new Position ( $dataX, $dataY, $dataZ );
  220. }
  221. }
  222. return $this->signGoldPos;
  223. }
  224. public function getHiderGoldSignPos() {
  225. if ($this->signHiderGoldPos === null) {
  226. $dataX = $this->getConfig ( "bh_hider_podium_gold_x" );
  227. $dataY = $this->getConfig ( "bh_hider_podium_gold_y" );
  228. $dataZ = $this->getConfig ( "bh_hider_podium_gold_z" );
  229. if (empty ( $dataX ) || empty ( $dataY ) || empty ( $dataZ )) {
  230. return null;
  231. } else {
  232. $this->signHiderGoldPos = new Position ( $dataX, $dataY, $dataZ );
  233. }
  234. }
  235. return $this->signHiderGoldPos;
  236. }
  237. public function getHiderSilverSignPos() {
  238. if ($this->signHiderSilverPos === null) {
  239. $dataX = $this->getConfig ( "bh_hider_podium_silver_x" );
  240. $dataY = $this->getConfig ( "bh_hider_podium_silver_y" );
  241. $dataZ = $this->getConfig ( "bh_hider_podium_silver_z" );
  242. if (empty ( $dataX ) || empty ( $dataY ) || empty ( $dataZ )) {
  243. return null;
  244. } else {
  245. $this->signHiderSilverPos = new Position ( $dataX, $dataY, $dataZ );
  246. }
  247. }
  248. return $this->signHiderSilverPos;
  249. }
  250. public function getHiderBronseSignPos() {
  251. if ($this->signHiderBronsePos === null) {
  252. $dataX = $this->getConfig ( "bh_hider_podium_bronse_x" );
  253. $dataY = $this->getConfig ( "bh_hider_podium_bronse_y" );
  254. $dataZ = $this->getConfig ( "bh_hider_podium_bronse_z" );
  255. if (empty ( $dataX ) || empty ( $dataY ) || empty ( $dataZ )) {
  256. return null;
  257. } else {
  258. $this->signHiderBronsePos = new Position ( $dataX, $dataY, $dataZ );
  259. }
  260. }
  261. return $this->signHiderBronsePos;
  262. }
  263. public function getSeekerGoldSignPos() {
  264. if ($this->signSeekerGoldPos === null) {
  265. $dataX = $this->getConfig ( "bh_seeker_podium_gold_x" );
  266. $dataY = $this->getConfig ( "bh_seeker_podium_gold_y" );
  267. $dataZ = $this->getConfig ( "bh_seeker_podium_gold_z" );
  268. if (empty ( $dataX ) || empty ( $dataY ) || empty ( $dataZ )) {
  269. return null;
  270. } else {
  271. $this->signSeekerGoldPos = new Position ( $dataX, $dataY, $dataZ );
  272. }
  273. }
  274. return $this->signSeekerGoldPos;
  275. }
  276. public function getSeekerSilverSignPos() {
  277. if ($this->signSeekerSilverPos === null) {
  278. $dataX = $this->getConfig ( "bh_seeker_podium_silver_x" );
  279. $dataY = $this->getConfig ( "bh_seeker_podium_silver_y" );
  280. $dataZ = $this->getConfig ( "bh_seeker_podium_silver_z" );
  281. if (empty ( $dataX ) || empty ( $dataY ) || empty ( $dataZ )) {
  282. return null;
  283. } else {
  284. $this->signSeekerSilverPos = new Position ( $dataX, $dataY, $dataZ );
  285. }
  286. }
  287. return $this->signSeekerSilverPos;
  288. }
  289. public function getSeekerBronseSignPos() {
  290. if ($this->signSeekerBronsePos === null) {
  291. $dataX = $this->getConfig ( "bh_seeker_podium_bronse_x" );
  292. $dataY = $this->getConfig ( "bh_seeker_podium_bronse_y" );
  293. $dataZ = $this->getConfig ( "bh_seeker_podium_bronse_z" );
  294. if (empty ( $dataX ) || empty ( $dataY ) || empty ( $dataZ )) {
  295. return null;
  296. } else {
  297. $this->signSeekerBronsePos = new Position ( $dataX, $dataY, $dataZ );
  298. }
  299. }
  300. return $this->signSeekerBronsePos;
  301. }
  302. public function getHomeWorldName() {
  303. return $this->getConfig ( "blockhunt_home_world" );
  304. }
  305. public function isEnableSpanwToLobby() {
  306. $enableSpawnLobby = $this->getConfig ( "enable_spaw_lobby" );
  307. if ($enableSpawnLobby != null && strtolower ( $enableSpawnLobby ) == "yes") {
  308. return true;
  309. }
  310. return false;
  311. }
  312. public function getMinimalGameStartPlayers() {
  313. return $this->getConfig ( "minimal_game_players", 2 );
  314. }
  315. public function isEnableScheduledReset() {
  316. $runSchedule = $this->getConfig ( "reset_scheduler" );
  317. if ($runSchedule != null && $runSchedule == "ON") {
  318. return true;
  319. }
  320. return false;
  321. }
  322. public function getServerLobbyWorldName() {
  323. return $this->getConfig ( "server_lobby_world" );
  324. }
  325. public function getServerLobbyPos() {
  326. $lobbyX = $this->getConfig ( "server_lobby_x" );
  327. $lobbyY = $this->getConfig ( "server_lobby_y" );
  328. $lobbyZ = $this->getConfig ( "server_lobby_z" );
  329. if (empty ( $lobbyX ) || empty ( $lobbyY ) || empty ( $lobbyZ )) {
  330. return null;
  331. } else {
  332. return new Position ( $lobbyX, $lobbyY, $lobbyZ );
  333. }
  334. }
  335. public function getServerLobbySignPos() {
  336. $lobbyX = $this->getConfig ( "server_lobby_sign_x" );
  337. $lobbyY = $this->getConfig ( "server_lobby_sign_y" );
  338. $lobbyZ = $this->getConfig ( "server_lobby_sign_z" );
  339. if (empty ( $lobbyX ) || empty ( $lobbyY ) || empty ( $lobbyZ )) {
  340. return null;
  341. } else {
  342. return new Position ( $lobbyX, $lobbyY, $lobbyZ );
  343. }
  344. }
  345. }