Advertisement
Guest User

Untitled

a guest
Jan 25th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.58 KB | None | 0 0
  1. package com.shoukaseikyo.minenion;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.File;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.text.DateFormat;
  8. import java.text.SimpleDateFormat;
  9. import java.util.ArrayList;
  10. import java.util.Date;
  11. import java.util.HashMap;
  12. import java.util.logging.Logger;
  13.  
  14. import org.bukkit.Bukkit;
  15. import org.bukkit.ChatColor;
  16. import org.bukkit.GameMode;
  17. import org.bukkit.Location;
  18. import org.bukkit.World;
  19. import org.bukkit.block.Block;
  20. import org.bukkit.command.Command;
  21. import org.bukkit.command.CommandSender;
  22. import org.bukkit.util.config.Configuration;
  23. import org.bukkit.entity.Player;
  24. import org.bukkit.event.Event;
  25. import org.bukkit.inventory.Inventory;
  26. import org.bukkit.inventory.ItemStack;
  27. import org.bukkit.plugin.PluginManager;
  28. import org.bukkit.plugin.java.JavaPlugin;
  29.  
  30. public class Minenion extends JavaPlugin
  31. {
  32.  
  33. // Class attributes
  34. public ArrayList<Player> playerList = new ArrayList<Player>();
  35. public int gameStartTime = 0;
  36. public HashMap<Player,Integer> playerDie = new HashMap<Player,Integer>();
  37. public HashMap<Integer, Player> playerOnTower = new HashMap<Integer, Player>();
  38. public HashMap<Player, Integer> playerTeam = new HashMap<Player, Integer>();
  39. public HashMap<Player, Integer> playerExperience = new HashMap<Player, Integer>();
  40. public HashMap<Integer, Integer> teamControlledTower = new HashMap<Integer, Integer>();
  41. public HashMap<Integer, Integer> playerTowerTime = new HashMap<Integer, Integer>();
  42. public HashMap<Integer, Integer> playerScore = new HashMap<Integer, Integer>();
  43.  
  44. //Player Money
  45. public HashMap<Player, Integer> playersaccount = new HashMap<Player, Integer>();
  46.  
  47. // Player Class
  48. public HashMap<Player, String> playersclass = new HashMap<Player, String>();
  49. public HashMap<Player, Integer> playerclasslevel = new HashMap<Player, Integer>();
  50. public HashMap<Player, Boolean> playerclassskill = new HashMap<Player, Boolean>();
  51.  
  52. // Player Effects
  53. public HashMap<Player, String> playerseffects = new HashMap<Player, String>();
  54.  
  55. // FINAL GAME SCORE
  56. public HashMap<Player, Integer> PlayerKills = new HashMap<Player, Integer>();
  57. public HashMap<Player, Integer> PlayerDeath = new HashMap<Player, Integer>();
  58. public HashMap<Player, Integer> PlayerCapturedTowers = new HashMap<Player, Integer>();
  59. public HashMap<Player, Integer> PlayerDamageInflict = new HashMap<Player, Integer>();
  60. public HashMap<Player, Integer> PlayerDamage = new HashMap<Player, Integer>();
  61. public HashMap<Player, Integer> PlayerTimeOnPlate = new HashMap<Player, Integer>();
  62. public HashMap<Integer, Integer> TeamCapturedTowers = new HashMap<Integer, Integer>();
  63.  
  64. public int[] shopblocks = new int[4];
  65. public Location[] towerLocations = new Location[5];
  66. public Location blueTeamLocation;
  67. public Location purpleTeamLocation;
  68. public boolean start = false;
  69. public boolean check = false;
  70. public boolean logging = true;
  71. public boolean light = false;
  72. public boolean multiverse = false;
  73. public int taskId;
  74. Logger log = Logger.getLogger("Minecraft");
  75.  
  76. // Constants
  77. public static final int BLUE_TEAM = 1;
  78. public static final int PURPLE_TEAM = 2;
  79.  
  80. /*
  81. * Enable the plugin
  82. */
  83. public void onEnable()
  84. {
  85. // initialize plugin
  86. log.info("[MINENION] Plugin enabled");
  87. PluginManager pluginManager = getServer().getPluginManager();
  88.  
  89. // Desactivate the loggin system
  90. if(getConfig().getString("logging") != null && getConfig().getString("logging").toLowerCase().equals("false"))
  91. {
  92. log.info("LOGGING");
  93. logging = false;
  94. }
  95.  
  96. // Lightweight activation
  97. if(getConfig().getString("lightweight") != null && getConfig().getString("lightweight").toLowerCase().equals("true"))
  98. {
  99. log.info("LIGHTWEIGHT");
  100. light = true;
  101. }
  102.  
  103. // register entity and player listener
  104. MinenionEntityListener entityListener = new MinenionEntityListener(this);
  105. MinenionPlayerListener playerListener = new MinenionPlayerListener(this);
  106.  
  107. // register events
  108. pluginManager.registerEvent(Event.Type.ENTITY_DEATH, entityListener, Event.Priority.Normal, this);
  109. pluginManager.registerEvent(Event.Type.ENTITY_DAMAGE, entityListener, Event.Priority.Normal, this);
  110. pluginManager.registerEvent(Event.Type.PLAYER_INTERACT, playerListener, Event.Priority.Normal, this);
  111. pluginManager.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Event.Priority.Normal, this);
  112.  
  113. //
  114. loadPointsPos();
  115. }
  116.  
  117. /*
  118. * Disable the plugin
  119. */
  120. public void onDisable()
  121. {
  122. log.info("[MINENION] Plugin disabled");
  123. }
  124.  
  125.  
  126. /*
  127. * Log system management
  128. * @param input : text to write to the plug-in log file
  129. */
  130. public void mineLog(String input)
  131. {
  132. // initialize file
  133. File file = new File(this.getDataFolder(), "MatchLog.txt");
  134. BufferedWriter bwriter = null;
  135. FileWriter fwriter = null;
  136. try
  137. {
  138. // write in file
  139. file.createNewFile();
  140. fwriter = new FileWriter(file, true);
  141. bwriter = new BufferedWriter(fwriter);
  142. bwriter.write(input);
  143. bwriter.newLine();
  144. bwriter.close();
  145. }
  146. catch (IOException e)
  147. {
  148. e.printStackTrace();
  149. }
  150. }
  151.  
  152. /*
  153. * Schedule the minenion thread
  154. */
  155. public void setupGame()
  156. {
  157. @SuppressWarnings("unused")
  158. int taskId;
  159.  
  160. // initialize minenion thread task
  161. MinenionThread minenionThread = new MinenionThread(this);
  162.  
  163. // register the thread to the bukkit scheduler
  164. taskId = getServer().getScheduler().scheduleSyncRepeatingTask(this, minenionThread, 20L, 20L);
  165. }
  166.  
  167. /*
  168. * Management of plate near tower, capture and neutralize
  169. */
  170. public void checkPlate()
  171. {
  172. // loop on towers
  173. for(int i = 1; i <= 5; i++)
  174. {
  175. // if player not on the plate tower
  176. if(playerOnTower.get(i) == null)
  177. {
  178. playerTowerTime.put(i, 0);
  179. ColorTower(i, 0, false);
  180. }
  181. else
  182. {
  183. // if player is on the plate tower, add tower to player
  184. Player onPlatePlayer = playerOnTower.get(i);
  185. int team = playerTeam.get(onPlatePlayer);
  186. playerTowerTime.get(i);
  187.  
  188. // tower controlled by the team
  189. if(teamControlledTower.get(i) == team)
  190. {
  191. // the player defend the tower
  192. if(isStillOn(onPlatePlayer, i))
  193. {
  194. if(logging == true) mineLog(gameStartTime + " - " + onPlatePlayer.getName() + " : defending the tower #" +i + ".");
  195. ColorTower(i, team, false);
  196. addTimeOnPlate(onPlatePlayer);
  197. }
  198. else
  199. {
  200. // the player leave the tower
  201. if(logging == true) mineLog(gameStartTime + " - " + onPlatePlayer.getName() + " : has leave the tower #" +i + ".");
  202. playerOnTower.put(i, null);
  203. ColorTower(i, 0, false);
  204. }
  205. }
  206. else
  207. {
  208. // tower not controlled by the team
  209. if(isStillOn(onPlatePlayer, i))
  210. {
  211. // player capture the tower
  212. if(logging == true) mineLog(gameStartTime + " - " + onPlatePlayer.getName() + " : capturing the tower #" +i + ". " + playerTowerTime.get(i) + "/4");
  213. ColorTower(i, team, false);
  214. int time = playerTowerTime.get(i);
  215.  
  216. // tower neutralization
  217. if(time == 4 && teamControlledTower.get(i) != 0)
  218. {
  219. if(logging == true) mineLog(gameStartTime + " - The tower #" + i + " has been neutralise by " + onPlatePlayer.getName());
  220. // add control tower and time
  221. playerTowerTime.put(i, 0);
  222. teamControlledTower.put(i, 0);
  223. }
  224. else if(time < 4)
  225. {
  226. // increment tower control time
  227. playerTowerTime.put(i, (time+1));
  228. addTimeOnPlate(onPlatePlayer);
  229. }
  230. else
  231. {
  232. // get player and team
  233. int teamOfPlayer = playerTeam.get(onPlatePlayer);
  234. ChatColor Color;
  235. String teamTitle;
  236. if(teamOfPlayer == BLUE_TEAM)
  237. {
  238. teamTitle = "blue";
  239. Color = ChatColor.BLUE;
  240. }
  241. else
  242. {
  243. teamTitle = "purple";
  244. Color = ChatColor.DARK_PURPLE;
  245. }
  246. if(logging == true) mineLog(gameStartTime + " - The tower #" + i + " has been captured by " + onPlatePlayer.getName() + " in the " + teamTitle + "team");
  247. error(onPlatePlayer, Color + "The tower #"+ i + " has been captured by " + onPlatePlayer.getName(), true);
  248.  
  249. addcaptured(onPlatePlayer);
  250.  
  251. // player control the tower
  252. ColorTower(i, teamOfPlayer, true);
  253. teamControlledTower.put(i, teamOfPlayer);
  254. playerTowerTime.put(i, 0);
  255. }
  256. }
  257. else
  258. {
  259. if(logging == true) mineLog(gameStartTime + " - " + onPlatePlayer.getName() + " : has leave the tower #" +i + ".");
  260. // player leave the tower
  261. playerOnTower.put(i, null);
  262. playerTowerTime.put(i, 0);
  263. teamControlledTower.put(i, 0);
  264. ColorTower(i, 0, false);
  265. }
  266.  
  267. }
  268. }
  269. }
  270. }
  271.  
  272. /*
  273. * Loading the game setup from config.yml plug-in file
  274. */
  275. public void loadPointsPos()
  276. {
  277. // Checking if the file exists
  278. if(new File(this.getDataFolder(), "config.yml").exists() == false)
  279. {
  280. log.info("The config file don't exist in /plugins/Minenion/. The plugin will be disable.");
  281. this.setEnabled(false);
  282. }
  283. else if(getConfig().getString("towers.one") == null ||
  284. getConfig().getString("towers.two") == null ||
  285. getConfig().getString("towers.three") == null ||
  286. getConfig().getString("towers.four") == null ||
  287. getConfig().getString("towers.five") == null ||
  288. getConfig().getString("world") == null ||
  289. getConfig().getString("spawn.blue") == null ||
  290. getConfig().getString("spawn.purple") == null ||
  291. getConfig().getString("shop.skill") == null ||
  292. getConfig().getString("shop.weapon") == null)
  293. {
  294. // one or more parameter is missed
  295. log.info("The coordinates are empty in /plugins/Minenion/config.yml. The plugin will be disable.");
  296. this.setEnabled(false);
  297. }
  298. else
  299. {
  300. boolean worldLoaded = false;
  301. // Verification if Multiverse is installed
  302. if(multiverse == true)
  303. {
  304. // Checking if the world is loaded in Bukkit
  305. for(World w: Bukkit.getServer().getWorlds())
  306. {
  307. if(w.getName().equals(getConfig().getString("world")))
  308. {
  309. worldLoaded = true;
  310. multiverse = false;
  311. break;
  312. }
  313. }
  314. }
  315. else if(new File("plugins\\Multiverse-Core", "config.yml").exists())
  316. {
  317. multiverse = true;
  318. }
  319. else
  320. {
  321. // Checking if the world is loaded in Bukkit
  322. for(World w: Bukkit.getServer().getWorlds())
  323. {
  324. if(w.getName().equals(getConfig().getString("world")))
  325. {
  326. worldLoaded = true;
  327. break;
  328. }
  329. }
  330. }
  331.  
  332. if(multiverse == true)
  333. {
  334. log.info("[MINENION] Do a \"/mn multiverse\" to load the coordinates.");
  335. return;
  336. }
  337.  
  338. // The world isn't loaded
  339. if(worldLoaded == false)
  340. {
  341. log.info("[MINENION] The world " + getConfig().getString("world") + " isn't loaded. The plugin will be disable.");
  342. log.info("[MINENION] Note, if you use Multiverse, load the world in its setting before installing this plugin.");
  343. this.setEnabled(false);
  344. return;
  345. }
  346. // loading the world
  347. String WORLD = getConfig().getString("world");
  348.  
  349. // loading the position of towers and spawns
  350. String[][] POS = {(getConfig().getString("towers.one")).split("/"),
  351. (getConfig().getString("towers.two")).split("/"),
  352. (getConfig().getString("towers.three")).split("/"),
  353. (getConfig().getString("towers.four")).split("/"),
  354. (getConfig().getString("towers.five")).split("/")};
  355.  
  356. // loading the start point of teams
  357. String[] B = (getConfig().getString("spawn.blue")).split("/");
  358. String[] P = (getConfig().getString("spawn.purple")).split("/");
  359.  
  360. // Generation of towers locations
  361. for(int i = 0; i <= 4; i++)
  362. {
  363. towerLocations[i] = new Location(Bukkit.getServer().getWorld(WORLD),
  364. Double.valueOf(POS[i][0]),
  365. Double.valueOf(POS[i][1]),
  366. Double.valueOf(POS[i][2]));
  367. }
  368.  
  369. // Generation of teams locations
  370. blueTeamLocation = new Location(Bukkit.getServer().getWorld(WORLD),
  371. Double.valueOf(B[0]),
  372. Double.valueOf(B[1]),
  373. Double.valueOf(B[2]));
  374. purpleTeamLocation = new Location(Bukkit.getServer().getWorld(WORLD),
  375. Double.valueOf(P[0]),
  376. Double.valueOf(P[1]),
  377. Double.valueOf(P[2]));
  378.  
  379. // Initialization of control tower
  380. for(int i = 1; i <= 5; i++)
  381. {
  382. playerOnTower.put(i, null);
  383. teamControlledTower.put(i, 0);
  384. playerTowerTime.put(i, 0);
  385. ColorTower(i, 0, true);
  386. ColorTower(i, 0, false);
  387. }
  388.  
  389. // Initialization of the shop's blocks
  390. shopblocks[0] = Integer.valueOf(getConfig().getString("shop.weapon").split("/")[0]);
  391. shopblocks[1] = Integer.valueOf(getConfig().getString("shop.skill").split("/")[0]);
  392. shopblocks[2] = 0;
  393. shopblocks[3] = 0;
  394. // Check if there is damage on blocks
  395. if(Integer.valueOf(getConfig().getString("shop.weapon").split("/")[1]) != 0)
  396. {
  397. shopblocks[2] = Integer.valueOf(getConfig().getString("shop.weapon").split("/")[1]);
  398. }
  399. if(Integer.valueOf(getConfig().getString("shop.skill").split("/")[1]) != 0)
  400. {
  401. shopblocks[3] = Integer.valueOf(getConfig().getString("shop.skill").split("/")[1]);
  402. }
  403.  
  404. // Initialization the teams scores
  405. playerScore.put(BLUE_TEAM, 500);
  406. playerScore.put(PURPLE_TEAM, 500);
  407. }
  408. }
  409.  
  410. /*
  411. * Change the color of a tower
  412. * @param tower : the number of the tower
  413. * @param team : the color of team who control the tower
  414. */
  415. public void ColorTower(int tower, int team, boolean cube)
  416. {
  417. int material = 0;
  418. int height = 17;
  419. int maxheight = 0;
  420. byte color = (byte)0x0;
  421. Block block;
  422.  
  423. // Set color for the team
  424. if(team == BLUE_TEAM)
  425. {
  426. color = (byte)0xB;
  427. material = 35;
  428. }
  429. if(team == PURPLE_TEAM)
  430. {
  431. color = (byte)0x2;
  432. material = 35;
  433. }
  434.  
  435. // if the tower is only controlled
  436. if(cube == true)
  437. {
  438. // set height to 13
  439. material = 35;
  440. height = 13;
  441. maxheight = 2;
  442. }
  443. // Get coordinates of towers
  444. World world = towerLocations[0].getWorld();
  445. int xPosTower = (int) (towerLocations[tower-1].getX()+1);
  446. int yPosTower = (int) (towerLocations[tower-1].getY()+height);
  447. int zPosTower = (int) (towerLocations[tower-1].getZ()+1);
  448.  
  449. // Apply color to the tower
  450. for(int x = xPosTower; x >= (xPosTower-2); x--)
  451. {
  452. for(int y = yPosTower; y <= (yPosTower+maxheight); y++)
  453. {
  454. for(int z = zPosTower; z >= (zPosTower-2); z--)
  455. {
  456. block = world.getBlockAt(x, y, z);
  457. block.setTypeIdAndData(material, color, false);
  458. }
  459. }
  460. }
  461. }
  462.  
  463. /*
  464. * Reset experience of a player
  465. * @param player : the player how to reset experience
  466. */
  467. public void resetExperience(Player player)
  468. {
  469. // reset the player experience
  470. player.setLevel(0);
  471. player.setExp(0);
  472. player.setTotalExperience(0);
  473. player.giveExp(playerExperience.get(player));
  474. }
  475.  
  476. /*
  477. * Management of game/team score
  478. */
  479. public void scoreManagement()
  480. {
  481. String[] controledTowerScore = towerControledScore().split("/");
  482. int blueScore = Integer.valueOf(controledTowerScore[0]);
  483. int purpleScore = Integer.valueOf(controledTowerScore[1]);
  484.  
  485. if(blueScore > purpleScore)
  486. {
  487. // if blue team had more controlled tower than purple team
  488. int actualControlPower = playerScore.get(2);
  489. int scoreGap = blueScore - purpleScore;
  490.  
  491. // in function of controlled tower score gap, remove score points to player
  492. if(scoreGap == 1)
  493. {
  494. playerScore.put(2, (playerScore.get(2) - 1));
  495. }
  496. else if(scoreGap == 2)
  497. {
  498. playerScore.put(2, (playerScore.get(2) - 2));
  499. }
  500. else if(scoreGap == 3)
  501. {
  502. playerScore.put(2, (playerScore.get(2) - 3));
  503. }
  504. else if(scoreGap == 4)
  505. {
  506. playerScore.put(2, (playerScore.get(2) - 5));
  507. }
  508. else if(scoreGap == 5)
  509. {
  510. playerScore.put(2, (playerScore.get(2) - 10));
  511. }
  512.  
  513. // send to console the new power balance
  514. int newControlPower = playerScore.get(2);
  515. int lostControlPower = actualControlPower - newControlPower;
  516. if(logging == true) mineLog(gameStartTime + " - The purple Nexus losted " + lostControlPower + "HP, " + newControlPower + "/500");
  517. }
  518. else if (blueScore < purpleScore)
  519. {
  520. // if purple team had more controlled tower than blue team
  521. int actualControlPower = playerScore.get(1);
  522. int scoreGap = purpleScore - blueScore;
  523.  
  524. // in function of controlled tower score gap, remove score points to player
  525. if(scoreGap == 1)
  526. {
  527. playerScore.put(1, (playerScore.get(1) - 1));
  528. }
  529. if(scoreGap == 2)
  530. {
  531. playerScore.put(1, (playerScore.get(1) - 2));
  532. }
  533. if(scoreGap == 3)
  534. {
  535. playerScore.put(1, (playerScore.get(1) - 3));
  536. }
  537. if(scoreGap == 4)
  538. {
  539. playerScore.put(1, (playerScore.get(1) - 5));
  540. }
  541. if(scoreGap == 5)
  542. {
  543. playerScore.put(1, (playerScore.get(1) - 10));
  544. }
  545.  
  546. // send to console the new power balance
  547. int newControlPower = playerScore.get(1);
  548. int lostControlPower = actualControlPower - newControlPower;
  549. if(logging == true) mineLog(gameStartTime + " - The blue Nexus losted " + lostControlPower + "HP, " + newControlPower + "/500");
  550. }
  551.  
  552. // lost game for blue team
  553. if(playerScore.get(1) <= 0)
  554. {
  555. start = false;
  556. // loop for player list
  557. for(Player player : playerList)
  558. {
  559. if(playerTeam.get(player) == 1)
  560. {
  561. // kicking and messaging the players
  562. player.kickPlayer("You lost !");
  563. if(logging == true) mineLog(gameStartTime + " - The blue Nexus has been destroyed ! The blue team lost.");
  564. if(logging == true) mineLog(gameStartTime + " - The game has stopped at : " + getDateTime());
  565. if(logging == true) mineLog("-------------------------");
  566.  
  567. // Generating score file
  568. if(logging == true) GenerateScore();
  569.  
  570. // unregister the minenion thread task
  571. getServer().getScheduler().cancelTask(taskId);
  572. }
  573. }
  574. }
  575.  
  576. // lost fame for purple team
  577. if(playerScore.get(2) <= 0)
  578. {
  579. start = false;
  580. // loop for player list
  581. for(Player player : playerList)
  582. {
  583. if(playerTeam.get(player) == 2)
  584. {
  585. // kicking and messaging the players
  586. player.kickPlayer("You lost !");
  587. if(logging == true) mineLog(gameStartTime + " - The purple Nexus has been destroyed ! The purple team lost.");
  588. if(logging == true) mineLog(gameStartTime + " - The game has stopped at : " + getDateTime());
  589. if(logging == true) mineLog("-------------------------");
  590.  
  591. // Generating score file
  592. if(logging == true) GenerateScore();
  593.  
  594. // unregister the minenion thread task
  595. getServer().getScheduler().cancelTask(taskId);
  596. }
  597. }
  598. }
  599. }
  600.  
  601. /*
  602. * Publish error message to the console player or broadcast
  603. * @param player : the name of the player how receive the message
  604. * @param message : the message to send
  605. * @param broadcast : true for broadcast all players, false for the player only
  606. */
  607. public void error(Player player, String message, boolean broadcast)
  608. {
  609. if(! broadcast)
  610. {
  611. // message to player
  612. player.sendMessage(message);
  613. }
  614. else
  615. {
  616. // message to broadcast
  617. getServer().broadcastMessage(message);
  618. }
  619. }
  620.  
  621. /*
  622. * Setup all the players to start the game
  623. */
  624. public void setupPlayers()
  625. {
  626. // setup team towers captured to 0
  627. TeamCapturedTowers.put(BLUE_TEAM, 0);
  628. TeamCapturedTowers.put(PURPLE_TEAM, 0);
  629.  
  630. // class attributes
  631. ItemStack itemStack;
  632. String classOfPlayer;
  633.  
  634. // loop for all players
  635. for(Player player : playerList)
  636. {
  637. // initialize player characteristics to play
  638. player.setGameMode(GameMode.SURVIVAL);
  639. player.setHealth(20);
  640. player.setFoodLevel(20);
  641.  
  642. if(light == false)
  643. {
  644. createaccount(player);
  645. player.setLevel(0);
  646. player.setExp(0);
  647. player.getInventory().clear();
  648. player.setTotalExperience(0);
  649. playerExperience.put(player, 0);
  650. PlayerKills.put(player, 0);
  651. PlayerDeath.put(player, 0);
  652. PlayerDamageInflict.put(player, 0);
  653. PlayerDamage.put(player, 0);
  654. PlayerTimeOnPlate.put(player, 0);
  655. PlayerCapturedTowers.put(player, 0);
  656.  
  657. // get inventory and class of player
  658. Inventory playerInventory = player.getInventory();
  659. classOfPlayer = getClass(player);
  660.  
  661. // ARCHER
  662. if(classOfPlayer.equals("archer"))
  663. {
  664. // create an arrows stack (64 pieces) and put it to player inventory (at position 9)
  665. itemStack = new ItemStack(262, 64);
  666. playerInventory.setItem(9, itemStack);
  667.  
  668. // create a bow stack (one piece) and put it to player inventory (at position 0)
  669. itemStack = new ItemStack(261, 1);
  670. playerInventory.setItem(0, itemStack);
  671.  
  672. }
  673.  
  674. // SWORDMAN
  675. if(classOfPlayer.equals("swordsman"))
  676. {
  677. // create a diamond sword stack (one piece) and put it to player inventory (at position 0)
  678. itemStack = new ItemStack(276, 1);
  679. playerInventory.setItem(0, itemStack);
  680. }
  681.  
  682. // TANK
  683. if(classOfPlayer.equals("tank"))
  684. {
  685. // create a wood stick stack (one piece) and put it to player inventory (at position 0)
  686. itemStack = new ItemStack(280, 1);
  687. playerInventory.setItem(0, itemStack);
  688. }
  689.  
  690. // UCKER
  691. if(classOfPlayer.equals("ucker"))
  692. {
  693. // create a diamond axe stack (one piece) and put it to player inventory (at position 0)
  694. itemStack = new ItemStack(279, 1);
  695. playerInventory.setItem(0, itemStack);
  696. }
  697. }
  698.  
  699. // move player to blue team start point
  700. if(playerTeam.get(player) == BLUE_TEAM)
  701. {
  702. player.teleport(blueTeamLocation);
  703. if(logging == true) mineLog(gameStartTime + " - " + player.getName() + "is in BLUE team.");
  704. }
  705.  
  706. // move player to blue team start point
  707. if(playerTeam.get(player) == PURPLE_TEAM)
  708. {
  709. player.teleport(purpleTeamLocation);
  710. if(logging == true) mineLog(gameStartTime + " - " + player.getName() + "is in PURPLE team.");
  711. }
  712. }
  713.  
  714. // reset game time
  715. gameStartTime = 0;
  716. }
  717.  
  718. /*
  719. * Determine the number of tower where player is
  720. * @param playerLocation : the location of player
  721. * @return i : the tower number
  722. */
  723. public int inWhichZone(Location playerLocation)
  724. {
  725. double X = playerLocation.getX();
  726. double Y = playerLocation.getY();
  727. double Z = playerLocation.getZ();
  728.  
  729. // loop the towers
  730. for(int i = 1; i <= 5; i++)
  731. {
  732. // check if around the tower
  733. if(X >= (towerLocations[i-1].getX()-7)
  734. && X <= (towerLocations[i-1].getX()+7)
  735. && Y >= (towerLocations[i-1].getY())
  736. && Y <= (towerLocations[i-1].getY()+3)
  737. && Z >= (towerLocations[i-1].getZ()-7)
  738. && Z <= (towerLocations[i-1].getZ()+7))
  739. {
  740. // Return tower number
  741. return (i);
  742. }
  743. }
  744. // No towers near player
  745. return 0;
  746. }
  747.  
  748. /*
  749. * Count player in a team
  750. * @param teamNumber : the number of the team (1 for blue, 2 for purple)
  751. * @return playerCount : the count of player for the chosen team
  752. */
  753. public int countPlayerTeam(int teamNumber)
  754. {
  755. int playerCount = 0;
  756.  
  757. // loop players list
  758. for(Player player : playerList)
  759. {
  760. // cumulate amount of players for the chosen team
  761. if(playerTeam.get(player) == teamNumber)
  762. {
  763. playerCount++;
  764. }
  765. }
  766. return playerCount;
  767. }
  768.  
  769. /*
  770. * Calculate the controlled tower for blue/purple team
  771. * @return : score of controlled tower (blue score / purple score)
  772. */
  773. public String towerControledScore()
  774. {
  775. int blueControledTower = 0;
  776. int purpleControledTower = 0;
  777. int controled = 0;
  778. String towerScore;
  779.  
  780. // loop for towers
  781. for(int i = 1; i <= 5; i++)
  782. {
  783. controled = teamControlledTower.get(i);
  784. if(controled == 1)
  785. {
  786. // tower controlled by blue team
  787. blueControledTower++;
  788. }
  789. if(controled == 2)
  790. {
  791. // tower controlled by purple team
  792. purpleControledTower++;
  793. }
  794. }
  795.  
  796. // generate the score
  797. towerScore = blueControledTower+"/"+purpleControledTower;
  798. return towerScore;
  799.  
  800. }
  801.  
  802. /*
  803. * Get the date/time
  804. * @return date : the current date/time
  805. */
  806. private String getDateTime()
  807. {
  808. // generate current date/time
  809. DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
  810. Date date = new Date();
  811. return dateFormat.format(date);
  812. }
  813.  
  814. /*
  815. * Get the byte from int
  816. * @argument damage : int to get byte from
  817. * @return damage2byte : byte
  818. */
  819. public byte damage2byte(int damage)
  820. {
  821. byte data = (byte)0x0;
  822. if(damage == 0)
  823. {
  824. return data;
  825. }
  826. if(damage == 1) data = (byte)0x1;
  827. if(damage == 2) data = (byte)0x2;
  828. if(damage == 3) data = (byte)0x3;
  829. if(damage == 4) data = (byte)0x4;
  830. if(damage == 5) data = (byte)0x5;
  831. if(damage == 6) data = (byte)0x6;
  832. if(damage == 7) data = (byte)0x7;
  833. if(damage == 8) data = (byte)0x8;
  834. if(damage == 9) data = (byte)0x9;
  835. if(damage == 10) data = (byte)0xA;
  836. if(damage == 11) data = (byte)0xB;
  837. if(damage == 12) data = (byte)0xC;
  838. if(damage == 13) data = (byte)0xD;
  839. if(damage == 14) data = (byte)0xE;
  840. if(damage == 15) data = (byte)0xF;
  841.  
  842. return data;
  843. }
  844.  
  845. /*
  846. * Check if the player is in a tower zone, on a pressure plate
  847. * @param player : the player to check
  848. * @param tower : the number of the tower
  849. * @return stillOn : true if the player still on
  850. */
  851. public boolean isStillOn(Player player, int tower)
  852. {
  853. // check if player is in a tower zone, on a pressure plate (id=70)
  854. if(player.getLocation().getBlock().getTypeId() == 70 && inWhichZone(player.getLocation()) == tower)
  855. {
  856. // the player still on
  857. return true;
  858. }
  859. // player is off
  860. return false;
  861. }
  862.  
  863. /*
  864. * Check if a player is online
  865. * @param player : the player to check if online
  866. * @return isOnline : true if the player is online
  867. */
  868. public boolean isOnline(String Player)
  869. {
  870. if (getServer().getPlayer(Player) == null)
  871. {
  872. // player offline
  873. return false;
  874. }
  875. else
  876. {
  877. // player online
  878. return true;
  879. }
  880. }
  881.  
  882. // CASH MANAGEMENT
  883.  
  884. /*
  885. * withdraw an amount from the player account
  886. * @param player : the player who to remove money
  887. * @param amount : the amount of money
  888. * @return withdraw : true if the transaction is working
  889. */
  890. public void withdraw(Player player, int amount)
  891. {
  892. if(hasaccount(player))
  893. {
  894. if(canafford(player, amount))
  895. {
  896. playersaccount.put(player, (playersaccount.get(player) - amount));
  897. }
  898. }
  899. }
  900.  
  901. /*
  902. * Give an amount to the player account
  903. * @param player : the player who to add money
  904. * @param amount : the amount of money
  905. */
  906. public void give(Player player, int amount)
  907. {
  908. if(hasaccount(player))
  909. {
  910. playersaccount.put(player, (playersaccount.get(player) + amount));
  911. }
  912. }
  913.  
  914. /*
  915. * if the player can afford the price
  916. * @param player : the player who can afford
  917. * @param amount : the amount of money
  918. * @return canafford : true if the player can buy
  919. */
  920. public boolean canafford(Player player, int amount)
  921. {
  922. if(hasaccount(player))
  923. {
  924. if(has(player) >= amount)
  925. {
  926. return true;
  927. }
  928. return false;
  929. }
  930. return false;
  931. }
  932.  
  933. /*
  934. * Create a account for the player
  935. * @param player : the player who need an account
  936. */
  937. public void createaccount(Player player)
  938. {
  939. playersaccount.put(player, 0);
  940. }
  941.  
  942. /*
  943. * Check if the player has an account
  944. * @param player : the player who has an account
  945. * @return hasaccount : true if the player has an account
  946. */
  947. public boolean hasaccount(Player player)
  948. {
  949. if(playersaccount.containsKey(player))
  950. {
  951. return true;
  952. }
  953. return false;
  954. }
  955.  
  956. /*
  957. * Return the money in the player account
  958. * @param player : the player who has how much
  959. * @return has : the money the player has
  960. */
  961. public int has(Player player)
  962. {
  963. if(hasaccount(player))
  964. {
  965. return playersaccount.get(player);
  966. }
  967. return 0;
  968. }
  969.  
  970. // CLASSES MANAGEMENT
  971.  
  972. /*
  973. * get if the player have the ability to use his skill
  974. * @argument player : the player to test
  975. * @return getSkill : true if the player has the ability
  976. */
  977. public boolean getSkill(Player player)
  978. {
  979. return playerclassskill.get(player);
  980. }
  981.  
  982. /*
  983. * set the player ability to use his skill to true
  984. * @argument player : player to give skill
  985. */
  986. public void setSkillTrue(Player player)
  987. {
  988. playerclassskill.put(player, true);
  989. }
  990.  
  991. /*
  992. * set the class level of the player
  993. * @argument player : player to set level
  994. * @argument level : the level to set
  995. */
  996. public void setLevel(Player player, int level)
  997. {
  998. playerclasslevel.put(player, level);
  999. }
  1000.  
  1001. /*
  1002. * get the class level of the player
  1003. * @argument player : the player class level to get
  1004. */
  1005. public int getLevel(Player player)
  1006. {
  1007. return playerclasslevel.get(player);
  1008. }
  1009.  
  1010. /*
  1011. * get the stats of the class with the player
  1012. * @argument player : the player who need stats
  1013. * @argument classe : the class the player have
  1014. */
  1015. public String stats(Player player)
  1016. {
  1017. String statistics = "0/0";
  1018. String classe = playersclass.get(player);
  1019. int level = player.getLevel();
  1020. int inHand = player.getInventory().getItemInHand().getTypeId();
  1021. int attack = 0;
  1022. int defense = 0;
  1023. if(classe.equals("archer"))
  1024. {
  1025. // calculate attack and defense
  1026. attack = (int) Math.floor(4*Math.log(15*level)+4);
  1027. defense = (int) Math.floor(0.1*level);
  1028.  
  1029. // calculate limits of attack/defense
  1030. if(inHand == 0) attack = 1;
  1031. if(getLevel(player) == 1 && attack > 6) attack = 6;
  1032. if(getLevel(player) == 2 && attack > 12) attack = 12;
  1033. if(attack > 19) attack = 19;
  1034. if(defense > 7) defense = 7;
  1035. }
  1036. if(classe.equals("swordsman"))
  1037. {
  1038. // calculate attack and defense
  1039. attack = (int) Math.floor(0.0019*(level*level)+4);
  1040. defense = (int) Math.floor(0.45*level+2);
  1041.  
  1042. // calculate limits of attack/defense
  1043. if(inHand == 0) attack = 1;
  1044. if(getLevel(player) == 1 && attack > 7) attack = 7;
  1045. if(inHand == 267) attack = 15;
  1046. if(attack > 19) attack = 19;
  1047. if(defense > 12) defense = 12;
  1048. }
  1049. if(classe.equals("ucker"))
  1050. {
  1051. // calculate attack and defense
  1052. attack = (int) Math.floor(0.8*level+5);
  1053. defense = (int) Math.floor(0.8*level);
  1054.  
  1055. // calculate limits of attack/defense
  1056. if(inHand == 0) attack = 1;
  1057. if(attack > 19) attack = 19;
  1058. if(defense > 8) defense = 8;
  1059.  
  1060. }
  1061. if(classe.equals("tank"))
  1062. {
  1063. // calculate attack and defense
  1064. attack = (int) Math.floor(0.1*level+2);
  1065. defense = (int) Math.floor(0.7*level+4);
  1066.  
  1067. // calculate limits of attack/defense
  1068. if(inHand == 0) attack = 1;
  1069. //if(inHand == 272) attack = 3;
  1070. //if(inHand == 267) attack = 7;
  1071. if(attack > 10) attack = 10;
  1072. if(defense > 17) defense = 17;
  1073. }
  1074. // generate statistics
  1075. statistics = attack + "/" + defense;
  1076. return statistics;
  1077. }
  1078.  
  1079. /*
  1080. * remove the class from the player
  1081. * @argument player : the player to retire a class
  1082. */
  1083. public void removeclass(Player player)
  1084. {
  1085. // set to lower case to not get errors
  1086. if(hasclass(player))
  1087. {
  1088. playersclass.remove(player);
  1089. }
  1090. }
  1091.  
  1092. /*
  1093. * Get the player class
  1094. * @argument player
  1095. * @return getClass : class
  1096. */
  1097. public String getClass(Player player)
  1098. {
  1099. if(hasclass(player))
  1100. {
  1101. return playersclass.get(player);
  1102. }
  1103. return null;
  1104. }
  1105.  
  1106. /*
  1107. * set the class to the player
  1108. * @argument player : the player who need a class
  1109. * @argument Class : the given class
  1110. */
  1111. public void setclass(Player player, String Class)
  1112. {
  1113. // set to lower case to not get errors
  1114. String Classe = Class.toLowerCase();
  1115. if(exist(Classe))
  1116. {
  1117. if(!hasclass(player))
  1118. {
  1119. playersclass.put(player, Classe);
  1120. playerclasslevel.put(player, 1);
  1121. playerclassskill.put(player, false);
  1122. }
  1123. }
  1124. }
  1125.  
  1126. /*
  1127. * if the player has a class
  1128. * @argument player : the player to test
  1129. * @return hasclass : true if the player has a class
  1130. */
  1131. public boolean hasclass(Player player)
  1132. {
  1133. if(playersclass.containsKey(player))
  1134. {
  1135. return true;
  1136. }
  1137. return false;
  1138. }
  1139.  
  1140. /*
  1141. * if the class exist
  1142. * @argument Class : Class to test
  1143. * @return exist : true if the class exist
  1144. */
  1145. public boolean exist(String Classe)
  1146. {
  1147. if(Classe.equals("archer") ||
  1148. Classe.equals("swordsman") ||
  1149. Classe.equals("ucker") ||
  1150. Classe.equals("tank"))
  1151. {
  1152. return true;
  1153. }
  1154. return false;
  1155. }
  1156.  
  1157. //EFFECTS MANAGEMENT
  1158.  
  1159. public String getEffect(Player player)
  1160. {
  1161. if(stillEffect(player))
  1162. {
  1163. return playerseffects.get(player).split("/")[0];
  1164. }
  1165. return "none";
  1166. }
  1167. /*
  1168. * if the effect is still effective
  1169. * @argument player : the player who will have the effect
  1170. * @return stillEffect : true if the effect is effective
  1171. */
  1172. public boolean stillEffect(Player player)
  1173. {
  1174. if(hasEffect(player))
  1175. {
  1176. String[] EffectTime = playerseffects.get(player).split("/");
  1177. String Effect = EffectTime[0];
  1178. int time = Integer.valueOf(EffectTime[1]);
  1179.  
  1180. //if the effect is poison
  1181. if(time == 0)
  1182. {
  1183. playerseffects.remove(player);
  1184. return false;
  1185. }
  1186. else
  1187. {
  1188. setEffect(player, Effect, (time-1));
  1189. return true;
  1190. }
  1191. }
  1192. return false;
  1193. }
  1194.  
  1195. /*
  1196. * get if the player has an effect
  1197. * @argument player
  1198. * @return hasEffect : true if the player has an effect
  1199. */
  1200. public boolean hasEffect(Player player)
  1201. {
  1202. if(playerseffects.containsKey(player))
  1203. {
  1204. return true;
  1205. }
  1206. return false;
  1207. }
  1208.  
  1209. /*
  1210. * set the effect to the player
  1211. * @argument player : the player who to set effect
  1212. * @argument effect : the effect to set
  1213. * @argument time : the duration of the effect
  1214. */
  1215. public void setEffect(Player player, String Effect, int time)
  1216. {
  1217. if(playerseffects.containsKey(player) == false || playerseffects.get(player).split("/")[0].equals(Effect))
  1218. {
  1219. playerseffects.put(player, Effect+"/"+time);
  1220. }
  1221. }
  1222.  
  1223. // SHOP MANAGEMENT
  1224.  
  1225. public void buyweapon(Player player)
  1226. {
  1227. if(getLevel(player) != 3)
  1228. {
  1229. int price = ((5000*getLevel(player)) - 2000);
  1230. if(canafford(player, price) == false)
  1231. {
  1232. player.sendMessage(ChatColor.RED + "You can't afford an upgrade to your weapon. " + ChatColor.YELLOW + "(Price : " + price + "$)");
  1233. return;
  1234. }
  1235. withdraw(player, price);
  1236. setLevel(player, (getLevel(player)+1));
  1237. player.sendMessage(ChatColor.YELLOW + "You paid " + price + "$ to upgrade your weapon to level " + getLevel(player) + " !");
  1238. return;
  1239. }
  1240. player.sendMessage(ChatColor.RED + "You can't upgrade your weapon anymore.");
  1241. return;
  1242. }
  1243.  
  1244. public void buyskill(Player player)
  1245. {
  1246. if(getSkill(player) == false)
  1247. {
  1248. int price = 12000;
  1249. if(canafford(player, price) == false)
  1250. {
  1251. player.sendMessage(ChatColor.RED + "You can't afford to buy your skill. " + ChatColor.YELLOW + "(Price : " + price + "$)");
  1252. return;
  1253. }
  1254. withdraw(player, price);
  1255. setSkillTrue(player);
  1256. player.sendMessage(ChatColor.YELLOW + "You paid " + price + "$ to obtain your skill !");
  1257. return;
  1258. }
  1259. player.sendMessage(ChatColor.RED + "There is no other skill to buy.");
  1260. return;
  1261. }
  1262.  
  1263. // FINAL GAME SCORE MANAGEMENT
  1264.  
  1265. /*
  1266. * Add a second to the time passed on plate
  1267. * @argument player : the player to add a second
  1268. */
  1269. public void addTimeOnPlate(Player player)
  1270. {
  1271. if(PlayerTimeOnPlate.containsKey(player) == false)
  1272. {
  1273. PlayerTimeOnPlate.put(player, 1);
  1274. return;
  1275. }
  1276. int TimeOnPlate = PlayerTimeOnPlate.get(player);
  1277. PlayerTimeOnPlate.put(player, (TimeOnPlate + 1));
  1278. }
  1279.  
  1280. /*
  1281. * Add an amount of damage to the player
  1282. * @argument player : the player to add amount of damage
  1283. * @argument damage : the amount of damage received
  1284. */
  1285. public void addDamageReceived(Player player, int damage)
  1286. {
  1287. if(PlayerDamage.containsKey(player) == false)
  1288. {
  1289. PlayerDamage.put(player, damage);
  1290. return;
  1291. }
  1292. int Damage = PlayerDamage.get(player);
  1293. PlayerDamage.put(player, (Damage + damage));
  1294. }
  1295.  
  1296. /*
  1297. * Add an amount of damage to the player
  1298. * @argument player : the player to add amount of damage
  1299. * @argument damage : the amount of damage inflicted
  1300. */
  1301. public void addDamageInflict(Player player, int damage)
  1302. {
  1303. if(PlayerCapturedTowers.containsKey(player) == false)
  1304. {
  1305. PlayerCapturedTowers.put(player, damage);
  1306. return;
  1307. }
  1308. int Damage = PlayerCapturedTowers.get(player);
  1309. PlayerCapturedTowers.put(player, (Damage + damage));
  1310. }
  1311.  
  1312. /*
  1313. * Add a captured tower to the counter of the player
  1314. * @argument player : the player to add a captured tower
  1315. */
  1316. public void addcaptured(Player player)
  1317. {
  1318. if(PlayerCapturedTowers.containsKey(player) == false)
  1319. {
  1320. PlayerCapturedTowers.put(player, 1);
  1321. return;
  1322. }
  1323. int TowerCounter = PlayerCapturedTowers.get(player);
  1324. PlayerCapturedTowers.put(player, (TowerCounter + 1));
  1325.  
  1326. int TEAM = playerTeam.get(player);
  1327. if(TeamCapturedTowers.containsKey(TEAM) == false)
  1328. {
  1329. TeamCapturedTowers.put(TEAM, 1);
  1330. return;
  1331. }
  1332. int TeamTowerCounter = TeamCapturedTowers.get(TEAM);
  1333. TeamCapturedTowers.put(TEAM, (TeamTowerCounter + 1));
  1334. }
  1335.  
  1336. /*
  1337. * Add a death to the counter of the player
  1338. * @argument player : the player to add a death
  1339. */
  1340. public void adddeath(Player player)
  1341. {
  1342. if(PlayerDeath.containsKey(player) == false)
  1343. {
  1344. PlayerDeath.put(player, 1);
  1345. return;
  1346. }
  1347. int DeathCounter = PlayerDeath.get(player);
  1348. PlayerDeath.put(player, (DeathCounter + 1));
  1349. }
  1350.  
  1351. /*
  1352. * Add a kill to the counter of the player
  1353. * @argument player : the player to add a kill
  1354. */
  1355. public void addkill(Player player)
  1356. {
  1357. if(PlayerKills.containsKey(player) == false)
  1358. {
  1359. PlayerKills.put(player, 1);
  1360. return;
  1361. }
  1362. int KillCounter = PlayerKills.get(player);
  1363. PlayerKills.put(player, (KillCounter + 1));
  1364. }
  1365.  
  1366. /*
  1367. * Generate the PlayersScore file when the game is finished
  1368. */
  1369. public void GenerateScore()
  1370. {
  1371. // initialize file
  1372. File file = new File(this.getDataFolder(), "PlayersScore.txt");
  1373. BufferedWriter bwriter = null;
  1374. FileWriter fwriter = null;
  1375. try
  1376. {
  1377. // write in file
  1378. file.createNewFile();
  1379. fwriter = new FileWriter(file, true);
  1380. bwriter = new BufferedWriter(fwriter);
  1381. bwriter.write("------------------------------------------");
  1382. bwriter.newLine();
  1383. bwriter.write("---------------|=TIME : " + gameStartTime + "=|---------------");
  1384. bwriter.newLine();
  1385. bwriter.write("------------------------------------------");
  1386. bwriter.newLine();
  1387. for(Player player : playerList)
  1388. {
  1389. bwriter.write("---Player : " + player.getName());
  1390. bwriter.newLine();
  1391. bwriter.write("------Kills : " + PlayerKills.get(player));
  1392. bwriter.newLine();
  1393. bwriter.write("------Death : " + PlayerDeath.get(player));
  1394. bwriter.newLine();
  1395. bwriter.write("------Towers captured : " + PlayerCapturedTowers.get(player) + "/" + TeamCapturedTowers.get(playerTeam.get(player)) + " towers captured by team");
  1396. bwriter.newLine();
  1397. bwriter.write("------Stats : Level : " + player.getLevel() + " - Inflicted damages : " + PlayerDamageInflict.get(player) + " - Damages received : " + PlayerDamage.get(player) + " - Money Obtained : " + has(player) + " - Total experience : " + player.getTotalExperience());
  1398. bwriter.newLine();
  1399. bwriter.write("------Time passed on towers : " + PlayerTimeOnPlate.get(player) + "/" + gameStartTime);
  1400. bwriter.newLine();
  1401. }
  1402. bwriter.close();
  1403. }
  1404. catch (IOException e)
  1405. {
  1406. e.printStackTrace();
  1407. }
  1408. }
  1409.  
  1410. /*
  1411. * Management of commands typed by a player in the console
  1412. * @param sender : player how send the command
  1413. * @param command : command send by the player (mn for minenion)
  1414. * @param label : command label
  1415. * @param args : arguments of command
  1416. * @return true if the command is known
  1417. */
  1418. public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
  1419. {
  1420. String cmd = command.getName().toLowerCase();
  1421. // if player send a minenion (mm) command
  1422. if (cmd.equals("mn") && sender instanceof Player)
  1423. {
  1424. if(multiverse == true && args[0].toLowerCase().equals("multiverse"))
  1425. {
  1426. loadPointsPos();
  1427. return true;
  1428. }
  1429. if(multiverse == true && (args.length >= 0))
  1430. {
  1431. error((Player)sender, ChatColor.RED + "Do /mn multiverse to reload the plugin with multiverse", false);
  1432. return true;
  1433. }
  1434. // ***********************
  1435. // HELP command
  1436. // ***********************
  1437. if(args.length == 0 || args[0].toLowerCase().equals("help"))
  1438. {
  1439. // write command help in the console
  1440. error((Player)sender, ChatColor.YELLOW + "Available commands", false);
  1441. if(light == true)
  1442. {
  1443. error((Player)sender, ChatColor.YELLOW + " /mn join <team> : " + ChatColor.WHITE + "Join the game.", false);
  1444. error((Player)sender, ChatColor.YELLOW + " <team> : " + ChatColor.BLUE + "BLUE" + ChatColor.YELLOW + " or " + ChatColor.DARK_PURPLE + "PURPLE", false);
  1445. }
  1446. else
  1447. {
  1448. error((Player)sender, ChatColor.YELLOW + " /mn join <team> <class> : " + ChatColor.WHITE + "Join the game.", false);
  1449. error((Player)sender, ChatColor.YELLOW + " <team> : " + ChatColor.BLUE + "BLUE" + ChatColor.YELLOW + " or " + ChatColor.DARK_PURPLE + "PURPLE", false);
  1450. error((Player)sender, ChatColor.YELLOW + " <class> : " + ChatColor.WHITE + "Archer, Swordsman, Tank, Ucker", false);
  1451. }
  1452. error((Player)sender, ChatColor.YELLOW + " /mn quit : " + ChatColor.WHITE + "Quit the current game.", false);
  1453. error((Player)sender, ChatColor.YELLOW + " /mn start : " + ChatColor.WHITE + "Start the current game.", false);
  1454.  
  1455. // if the player is a server operator, more commands
  1456. if(sender.isOp())
  1457. {
  1458. error((Player)sender, ChatColor.YELLOW + " /mn fstart : " + ChatColor.WHITE + "Force the game to start.", false);
  1459. error((Player)sender, ChatColor.YELLOW + " /mn stp : " + ChatColor.WHITE + "Stop the current game and reset the players list.", false);
  1460. }
  1461. return true;
  1462. }
  1463.  
  1464. // ***********************
  1465. // JOIN command
  1466. // ***********************
  1467. if(args[0].toLowerCase().equals("join"))
  1468. {
  1469. // if game is started
  1470. if(start == false)
  1471. {
  1472. // if the command sender is already in the player list
  1473. if(playerList.contains((Player)sender) == true)
  1474. {
  1475. error((Player) sender, ChatColor.RED + "You already joined the game.", false);
  1476. return true;
  1477. }
  1478.  
  1479. // check if the arguments to join are correct
  1480. if(light == false && (args.length < 3 || !(args[1].toLowerCase().equals("blue") || args[1].toLowerCase().equals("purple")) || !(args[2].toLowerCase().equals("archer") || args[2].toLowerCase().equals("swordsman") || args[2].toLowerCase().equals("tank") || args[2].toLowerCase().equals("ucker"))))
  1481. {
  1482. error((Player)sender, ChatColor.YELLOW + "/mn join <team> <class> : " + ChatColor.WHITE + "Join the game.", false);
  1483. error((Player)sender, ChatColor.YELLOW + " <team> : " + ChatColor.BLUE + "BLUE" + ChatColor.YELLOW + " or " + ChatColor.DARK_PURPLE + "PURPLE", false);
  1484. error((Player)sender, ChatColor.YELLOW + " <class> : " + ChatColor.WHITE + "Archer, Swordsman, Tank, Ucker", false);
  1485. return true;
  1486. }
  1487.  
  1488. if(light == true && (args.length < 2 || !(args[1].toLowerCase().equals("blue") || args[1].toLowerCase().equals("purple"))))
  1489. {
  1490. error((Player)sender, ChatColor.YELLOW + "/mn join <team> <class> : " + ChatColor.WHITE + "Join the game.", false);
  1491. error((Player)sender, ChatColor.YELLOW + " <team> : " + ChatColor.BLUE + "BLUE" + ChatColor.YELLOW + " or " + ChatColor.DARK_PURPLE + "PURPLE", false);
  1492. return true;
  1493. }
  1494.  
  1495. // team selection
  1496. int team = 0;
  1497. if(args[1].toLowerCase().equals("blue"))
  1498. {
  1499. team = BLUE_TEAM;
  1500. }
  1501. if(args[1].toLowerCase().equals("purple"))
  1502. {
  1503. team = PURPLE_TEAM;
  1504. }
  1505.  
  1506. String error;
  1507.  
  1508. // check if still slot in the team
  1509. if(countPlayerTeam(team) < 5)
  1510. {
  1511. // add player in the team
  1512. Player player = (Player)sender;
  1513. playerList.add(player);
  1514. playerTeam.put(player, team);
  1515.  
  1516. error = ChatColor.BLUE + sender.getName() + " has join the " + args[1] + " team !";
  1517.  
  1518. if(light == false)
  1519. {
  1520. // check the class of the player and set it
  1521. if(args[2].toLowerCase().equals("archer"))
  1522. {
  1523. setclass(player, "archer");
  1524. }
  1525. if(args[2].toLowerCase().equals("swordsman"))
  1526. {
  1527. setclass(player, "swordsman");
  1528. }
  1529. if(args[2].toLowerCase().equals("tank"))
  1530. {
  1531. setclass(player, "tank");
  1532. }
  1533. if(args[2].toLowerCase().equals("ucker"))
  1534. {
  1535. setclass(player, "ucker");
  1536. }
  1537.  
  1538. error = ChatColor.BLUE + sender.getName() + " has join the " + args[1] + " team as " + args[2] + " !";
  1539. }
  1540. error((Player)sender, error, true);
  1541. return true;
  1542. }
  1543. // there is no more space in the team
  1544. error((Player)sender, ChatColor.RED + "The Team is full !", false);
  1545. return true;
  1546. }
  1547. // the game has already started
  1548. error((Player)sender, ChatColor.RED + "The game is already started, you can't join now ! =(", false);
  1549. return true;
  1550. }
  1551.  
  1552. // ***********************
  1553. // QUIT command
  1554. // ***********************
  1555. if(args[0].toLowerCase().equals("quit"))
  1556. {
  1557. // if game is started
  1558. if(start == false)
  1559. {
  1560. // remove player from the game
  1561. Player player = (Player)sender;
  1562. // if the command sender is not in the player list
  1563. if(playerList.contains(player))
  1564. {
  1565. playerList.remove(player);
  1566. playerTeam.remove(player);
  1567. error((Player)sender, ChatColor.DARK_PURPLE + sender.getName() + " has quit the game !", true);
  1568. return true;
  1569. }
  1570. else
  1571. {
  1572. error(player, ChatColor.RED + "You aren't listed.", false);
  1573. return true;
  1574. }
  1575. }
  1576. // the game has already started
  1577. error((Player)sender, ChatColor.RED + "The game is already started, you can't quit now ! D=", false);
  1578. return true;
  1579. }
  1580.  
  1581. // ***********************
  1582. // START command
  1583. // ***********************
  1584. if(args[0].toLowerCase().equals("start"))
  1585. {
  1586. // if there is 2 team of 5 players and the game not already started
  1587. if((countPlayerTeam(1) + countPlayerTeam(2)) == 10 && start == false)
  1588. {
  1589. // start game
  1590. start = true;
  1591. if(logging == true) mineLog(gameStartTime + " - The game has started at : " + getDateTime());
  1592. for(int i = 1; i <= 5; i++)
  1593. {
  1594. playerOnTower.put(i, null);
  1595. teamControlledTower.put(i, 0);
  1596. playerTowerTime.put(i, 0);
  1597. ColorTower(i, 0, false);
  1598. ColorTower(i, 0, true);
  1599. }
  1600. playerScore.put(1, 500);
  1601. playerScore.put(2, 500);
  1602. setupPlayers();
  1603. setupGame();
  1604. error((Player)sender, ChatColor.YELLOW + "The game is started !", true);
  1605. return true;
  1606. }
  1607. // the game is already started or incomplete team
  1608. error((Player)sender, ChatColor.RED + "The teams are not complete OR the game is already started!", false);
  1609. return true;
  1610. }
  1611.  
  1612. // ***************************************************
  1613. // FSTART forced start command only for game operator
  1614. // ***************************************************
  1615. if(args[0].toLowerCase().equals("fstart") && sender.isOp() && playerList.contains((Player)sender))
  1616. {
  1617. // if game is started
  1618. if(start == false)
  1619. {
  1620. // start the game
  1621. start = true;
  1622. if(logging == true) mineLog(gameStartTime + " - The game has being forced to start at : " + getDateTime() + " WITH " + countPlayerTeam(BLUE_TEAM) + " blue players AND " + countPlayerTeam(PURPLE_TEAM) + " purple players");
  1623. for(int i = 1; i <= 5; i++)
  1624. {
  1625. playerOnTower.put(i, null);
  1626. teamControlledTower.put(i, 0);
  1627. playerTowerTime.put(i, 0);
  1628. ColorTower(i, 0, false);
  1629. ColorTower(i, 0, true);
  1630. }
  1631. playerScore.put(1, 500);
  1632. playerScore.put(2, 500);
  1633. setupPlayers();
  1634. setupGame();
  1635. error((Player)sender, ChatColor.YELLOW + "The game is started !", true);
  1636. return true;
  1637. }
  1638. // the game is already started
  1639. error((Player)sender, ChatColor.RED + "The game is already started!", false);
  1640. return true;
  1641. }
  1642.  
  1643. // *****************************************
  1644. // CHECK command for testing coordinates
  1645. // *****************************************
  1646. if(args[0].toLowerCase().equals("check"))
  1647. {
  1648. if(check == false)
  1649. {
  1650. check = true;
  1651. return true;
  1652. }
  1653. else
  1654. {
  1655. check = false;
  1656. return true;
  1657. }
  1658. }
  1659.  
  1660. // ************************************
  1661. // STOP command only for game operator
  1662. // ************************************
  1663. if(args[0].toLowerCase().equals("stop") && sender.isOp())
  1664. {
  1665. // if game is started
  1666. if(start == true)
  1667. {
  1668. // generate the final score
  1669. if(logging == true)
  1670. {
  1671. GenerateScore();
  1672. playersclass.clear();
  1673. playerclassskill.clear();
  1674. playerclasslevel.clear();
  1675. }
  1676. // clear players
  1677. playerList.clear();
  1678. playerTeam.clear();
  1679. // remove thread task of minennion
  1680. getServer().getScheduler().cancelTask(taskId);
  1681. // messageing the players
  1682. if(logging == true) mineLog(gameStartTime + " - The game has stopped at : " + getDateTime());
  1683. if(logging == true) mineLog("-------------------------");
  1684. error((Player)sender, ChatColor.RED + "The game has been stop ! =(", true);
  1685. start = false;
  1686. return true;
  1687. }
  1688. // the game is not started
  1689. error((Player)sender, ChatColor.RED + "The game isn't started !", false);
  1690. return true;
  1691. }
  1692. return true;
  1693. }
  1694. // unknown command
  1695. return false;
  1696. }
  1697. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement