Advertisement
Guest User

Untitled

a guest
Dec 31st, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.41 KB | None | 0 0
  1. package me.frederikbontved.reallife;
  2.  
  3. import java.io.IOException;
  4. import java.util.HashMap;
  5. import java.util.logging.Logger;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.ChatColor;
  9. import org.bukkit.Effect;
  10. import org.bukkit.Location;
  11. import org.bukkit.Material;
  12. import org.bukkit.command.Command;
  13. import org.bukkit.command.CommandSender;
  14. import org.bukkit.entity.Entity;
  15. import org.bukkit.entity.Minecart;
  16. import org.bukkit.entity.Player;
  17. import org.bukkit.event.EventHandler;
  18. import org.bukkit.event.Listener;
  19. import org.bukkit.event.block.Action;
  20. import org.bukkit.event.player.PlayerInteractEvent;
  21. import org.bukkit.event.player.PlayerQuitEvent;
  22. import org.bukkit.event.vehicle.VehicleBlockCollisionEvent;
  23. import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
  24. import org.bukkit.event.vehicle.VehicleUpdateEvent;
  25. import org.bukkit.plugin.java.JavaPlugin;
  26. import org.bukkit.util.Vector;
  27.  
  28. public class Reallifecars extends JavaPlugin implements Listener {
  29. Logger logger = Logger.getLogger("Minecraft");
  30. public static Reallifecars plugin;
  31. public HashMap<String, Boolean> railways = new HashMap<String, Boolean>();
  32. public HashMap<String, Location> railways_spawn = new HashMap<String, Location>();
  33. public HashMap<String, Location> railways_spawn_2 = new HashMap<String, Location>();
  34. public HashMap<String, Location> railways_spawn_3 = new HashMap<String, Location>();
  35. public HashMap<String, Location> railways_spawn_4 = new HashMap<String, Location>();
  36. public HashMap<String, Location> railways_spawn_5 = new HashMap<String, Location>();
  37. public HashMap<String, Location> railways_spawn_6 = new HashMap<String, Location>();
  38. public HashMap<String, Integer> railways_spawn_count = new HashMap<String, Integer>();
  39. public HashMap<String, Location> railways_stop = new HashMap<String, Location>();
  40. public HashMap<Location, String> railways_locations = new HashMap<Location, String>();
  41. public HashMap<String, String> railways_reward = new HashMap<String, String>();
  42. public HashMap<String, String> railways_players = new HashMap<String, String>();
  43. public HashMap<String, String> railways_players_2 = new HashMap<String, String>();
  44. public HashMap<String, Location> railways_finish = new HashMap<String, Location>();
  45. public HashMap<String, String> shop = new HashMap<String, String>();
  46. public HashMap<String, String> boost = new HashMap<String, String>();
  47.  
  48. @Override
  49. public void onEnable() {
  50. readData();
  51. this.logger.info("Cars has been enabled!");
  52. this.getServer().getPluginManager().registerEvents(this, this);
  53. this.getConfig().options().copyDefaults(true);
  54. saveConfig();
  55. }
  56. @Override
  57. public void onDisable() {
  58. this.logger.info("Cars has been disabled!");
  59. saveData();
  60. }
  61. private void readData() {
  62. try {
  63. HashMapSaver hs = new HashMapSaver(this);
  64.  
  65. railways = hs.get_railways();
  66. railways_spawn = hs.get_railways_spawn();
  67. railways_spawn_2 = hs.get_railways_spawn_2();
  68. railways_spawn_3 = hs.get_railways_spawn_3();
  69. railways_spawn_4 = hs.get_railways_spawn_4();
  70. railways_spawn_5 = hs.get_railways_spawn_5();
  71. railways_spawn_6 = hs.get_railways_spawn_6();
  72. railways_spawn_count = hs.get_railways_spawn_count();
  73. railways_stop = hs.get_railways_stop();
  74. railways_locations = hs.get_railways_locations();
  75. railways_reward = hs.get_railways_reward();
  76. railways_players = hs.get_railways_players();
  77. railways_players_2 = hs.get_railways_players_2();
  78. railways_finish = hs.get_railways_finish();
  79. shop = hs.get_shop();
  80. boost = hs.get_boost();
  81.  
  82. } catch (IOException e) {
  83. railways = new HashMap<>();
  84. railways_spawn = new HashMap<>();
  85. railways_spawn_2 = new HashMap<>();
  86. railways_spawn_3 = new HashMap<>();
  87. railways_spawn_4 = new HashMap<>();
  88. railways_spawn_5 = new HashMap<>();
  89. railways_spawn_6 = new HashMap<>();
  90. railways_spawn_count = new HashMap<>();
  91. railways_stop = new HashMap<>();
  92. railways_locations = new HashMap<>();
  93. railways_reward = new HashMap<>();
  94. railways_players = new HashMap<>();
  95. railways_players_2 = new HashMap<>();
  96. railways_finish = new HashMap<>();
  97. shop = new HashMap<>();
  98. boost = new HashMap<>();
  99.  
  100. this.logger.info("Could not find save data. Starts with empty values");
  101.  
  102. } catch (ClassNotFoundException e) {
  103. this.logger.severe(e.toString());
  104. }
  105. }
  106.  
  107. private void saveData() {
  108. try {
  109. HashMapSaver hs = new HashMapSaver(this);
  110.  
  111. hs.save_railways(railways);
  112. hs.save_railways_spawn(railways_spawn);
  113. hs.save_railways_spawn_2(railways_spawn_2);
  114. hs.save_railways_spawn_3(railways_spawn_3);
  115. hs.save_railways_spawn_4(railways_spawn_4);
  116. hs.save_railways_spawn_5(railways_spawn_5);
  117. hs.save_railways_spawn_6(railways_spawn_6);
  118. hs.save_railways_spawn_count(railways_spawn_count);
  119. hs.save_railways_stop(railways_stop);
  120. hs.save_railways_locations(railways_locations);
  121. hs.save_railways_reward(railways_reward);
  122. hs.save_railways_players(railways_players);
  123. hs.save_railways_players_2(railways_players_2);
  124. hs.save_railways_finish(railways_finish);
  125. hs.save_shop(shop);
  126. hs.save_boost(boost);
  127.  
  128. } catch (IOException e) {
  129. this.logger.severe(e.toString());
  130. }
  131. }
  132.  
  133. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  134. Player player = (Player) sender;
  135. if (cmd.getName().equalsIgnoreCase("c")) {
  136. if (args[0].equalsIgnoreCase("help")) {
  137. player.sendMessage(this.getConfig().getString("translation_1"));
  138. }
  139. if (args[0].equalsIgnoreCase("create")) {
  140. if (player.hasPermission("rlc.create")) {
  141. if (args.length == 2) {
  142. if (!(railways.containsKey(args[1]))) {
  143. railways.put(args[1], false);
  144. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_2").replace("&n", args[1]));
  145. player.sendMessage(ChatColor.GOLD + this.getConfig().getString("translation_3"));
  146. }
  147. else {
  148. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_4").replace("&n", args[1]));
  149. }
  150. }
  151. else {
  152. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_5"));
  153. }
  154. }
  155. }
  156. if (args[0].equalsIgnoreCase("spawn")) {
  157. if (player.hasPermission("rlc.spawn")) {
  158. if (args.length == 2) {
  159. if (railways.containsKey(args[1])) {
  160. if (!(railways_spawn.containsKey(args[1]))) {
  161. railways_spawn.put(args[1], player.getLocation());
  162. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_6").replace("&n", args[1]));
  163. player.sendMessage(ChatColor.GOLD + this.getConfig().getString("translation_7"));
  164. }
  165. else {
  166. railways_spawn.remove(args[1]);
  167. railways_spawn.put(args[1], player.getLocation());
  168. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_8").replace("&n", args[1]));
  169. }
  170. }
  171. else {
  172. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_9").replace("&n", args[1]));
  173. }
  174. }
  175. else {
  176. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_10"));
  177. }
  178. }
  179. }
  180. if (args[0].equalsIgnoreCase("spawn2")) {
  181. if (player.hasPermission("rlc.spawn")) {
  182. if (args.length == 2) {
  183. if (railways.containsKey(args[1])) {
  184. if (!(railways_spawn_2.containsKey(args[1]))) {
  185. railways_spawn_2.put(args[1], player.getLocation());
  186. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_6").replace("&n", args[1]));
  187. player.sendMessage(ChatColor.GOLD + this.getConfig().getString("translation_7"));
  188. }
  189. else {
  190. railways_spawn_2.remove(args[1]);
  191. railways_spawn_2.put(args[1], player.getLocation());
  192. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_8").replace("&n", args[1]));
  193. }
  194. }
  195. else {
  196. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_9").replace("&n", args[1]));
  197. }
  198. }
  199. else {
  200. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_10"));
  201. }
  202. }
  203. }
  204. if (args[0].equalsIgnoreCase("spawn3")) {
  205. if (player.hasPermission("rlc.spawn")) {
  206. if (args.length == 2) {
  207. if (railways.containsKey(args[1])) {
  208. if (!(railways_spawn_3.containsKey(args[1]))) {
  209. railways_spawn_3.put(args[1], player.getLocation());
  210. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_6").replace("&n", args[1]));
  211. player.sendMessage(ChatColor.GOLD + this.getConfig().getString("translation_7"));
  212. }
  213. else {
  214. railways_spawn_3.remove(args[1]);
  215. railways_spawn_3.put(args[1], player.getLocation());
  216. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_8").replace("&n", args[1]));
  217. }
  218. }
  219. else {
  220. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_9").replace("&n", args[1]));
  221. }
  222. }
  223. else {
  224. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_10"));
  225. }
  226. }
  227. }
  228. if (args[0].equalsIgnoreCase("spawn4")) {
  229. if (player.hasPermission("rlc.spawn")) {
  230. if (args.length == 2) {
  231. if (railways.containsKey(args[1])) {
  232. if (!(railways_spawn_4.containsKey(args[1]))) {
  233. railways_spawn_4.put(args[1], player.getLocation());
  234. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_6").replace("&n", args[1]));
  235. player.sendMessage(ChatColor.GOLD + this.getConfig().getString("translation_7"));
  236. }
  237. else {
  238. railways_spawn_4.remove(args[1]);
  239. railways_spawn_4.put(args[1], player.getLocation());
  240. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_8").replace("&n", args[1]));
  241. }
  242. }
  243. else {
  244. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_9").replace("&n", args[1]));
  245. }
  246. }
  247. else {
  248. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_10"));
  249. }
  250. }
  251. }
  252. if (args[0].equalsIgnoreCase("spawn5")) {
  253. if (player.hasPermission("rlc.spawn")) {
  254. if (args.length == 2) {
  255. if (railways.containsKey(args[1])) {
  256. if (!(railways_spawn_5.containsKey(args[1]))) {
  257. railways_spawn_5.put(args[1], player.getLocation());
  258. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_6").replace("&n", args[1]));
  259. player.sendMessage(ChatColor.GOLD + this.getConfig().getString("translation_7"));
  260. }
  261. else {
  262. railways_spawn_5.remove(args[1]);
  263. railways_spawn_5.put(args[1], player.getLocation());
  264. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_8").replace("&n", args[1]));
  265. }
  266. }
  267. else {
  268. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_9").replace("&n", args[1]));
  269. }
  270. }
  271. else {
  272. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_10"));
  273. }
  274. }
  275. }
  276. if (args[0].equalsIgnoreCase("spawn6")) {
  277. if (player.hasPermission("rlc.spawn")) {
  278. if (args.length == 2) {
  279. if (railways.containsKey(args[1])) {
  280. if (!(railways_spawn_6.containsKey(args[1]))) {
  281. railways_spawn_6.put(args[1], player.getLocation());
  282. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_6").replace("&n", args[1]));
  283. player.sendMessage(ChatColor.GOLD + this.getConfig().getString("translation_7"));
  284. }
  285. else {
  286. railways_spawn_6.remove(args[1]);
  287. railways_spawn_6.put(args[1], player.getLocation());
  288. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_8").replace("&n", args[1]));
  289. }
  290. }
  291. else {
  292. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_9").replace("&n", args[1]));
  293. }
  294. }
  295. else {
  296. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_10"));
  297. }
  298. }
  299. }
  300. if (args[0].equalsIgnoreCase("stop")) {
  301. if (player.hasPermission("rlc.stop")) {
  302. if (args.length == 2) {
  303. if (railways.containsKey(args[1])) {
  304. if (!(railways_stop.containsKey(args[1]))) {
  305. railways_stop.put(args[1], player.getLocation().getBlock().getLocation());
  306. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_11").replace("&n", args[1]));
  307. player.sendMessage(ChatColor.GOLD + this.getConfig().getString("translation_12"));
  308. }
  309. else {
  310. railways_stop.remove(args[1]);
  311. railways_stop.put(args[1], player.getLocation().getBlock().getLocation());
  312. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_13").replace("&n", args[1]));
  313. }
  314. }
  315. else {
  316. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_14").replace("&n", args[1]));
  317. }
  318. }
  319. else {
  320. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_15"));
  321. }
  322. }
  323. }
  324. if (args[0].equalsIgnoreCase("location")) {
  325. if (player.hasPermission("rlc.location")) {
  326. if (args.length == 2) {
  327. if (railways.containsValue(args[1])) {
  328. railways_locations.put(player.getLocation().getBlock().getLocation(), args[1]);
  329. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_48").replace("&n", args[1]));
  330. }
  331. else {
  332. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_14").replace("&n", args[1]));
  333. }
  334. }
  335. else {
  336. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_15"));
  337. }
  338. }
  339. }
  340. if (args[0].equalsIgnoreCase("finish")) {
  341. if (player.hasPermission("rlc.finish")) {
  342. if (args.length == 2) {
  343. if (railways.containsKey(args[1])) {
  344. if (!(railways_finish.containsKey(args[1]))) {
  345. railways_finish.put(args[1], player.getLocation().getBlock().getLocation());
  346. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_16").replace("&n", args[1]));
  347. player.sendMessage(ChatColor.GOLD + this.getConfig().getString("translation_17"));
  348. }
  349. else {
  350. railways_finish.remove(args[1]);
  351. railways_finish.put(args[1], player.getLocation().getBlock().getLocation());
  352. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_18").replace("&n", args[1]));
  353. }
  354. }
  355. else {
  356. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_19").replace("&n", args[1]));
  357. }
  358. }
  359. else {
  360. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_20"));
  361. }
  362. }
  363. }
  364. else if (args[0].equalsIgnoreCase("reward")) {
  365. if (player.hasPermission("rlc.reward")) {
  366. if (args.length == 3) {
  367. if (railways.containsKey(args[1])) {
  368. if (!(railways_reward.containsKey(args[1]))) {
  369. railways_reward.put(args[1], args[2]);
  370. player.sendMessage(this.getConfig().getString("translation_21").replace("&n", args[1]));
  371. player.sendMessage(ChatColor.GOLD + this.getConfig().getString("translation_22"));
  372. }
  373. else {
  374. railways_reward.remove(args[1]);
  375. railways_reward.put(args[1], args[2]);
  376. player.sendMessage(this.getConfig().getString("translation_23").replace("&n", args[1]));
  377. }
  378. }
  379. else {
  380. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_24").replace("&n", args[1]));
  381. }
  382. }
  383. else {
  384. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_25"));
  385. }
  386. }
  387. }
  388. else if (args[0].equalsIgnoreCase("remove")) {
  389. if (player.hasPermission("rlc.remove")) {
  390. if (args.length == 2) {
  391. if (railways.containsKey(args[1])) {
  392. railways.remove(args[1]);
  393. railways_spawn.remove(args[1]);
  394. railways_spawn_2.remove(args[1]);
  395. railways_spawn_3.remove(args[1]);
  396. railways_spawn_4.remove(args[1]);
  397. railways_spawn_5.remove(args[1]);
  398. railways_spawn_6.remove(args[1]);
  399. railways_spawn_count.remove(args[1]);
  400. railways_stop.remove(args[1]);
  401. railways_reward.remove(args[1]);
  402. railways_players_2.remove(args[1]);
  403. railways_finish.remove(args[1]);
  404. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_45").replace("&n", args[1]));
  405. }
  406. else {
  407. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_24").replace("&n", args[1]));
  408. }
  409. }
  410. else {
  411. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_25"));
  412. }
  413. }
  414. }
  415. else if (args[0].equalsIgnoreCase("close")) {
  416. if (player.hasPermission("rlc.close")) {
  417. if (args.length == 2) {
  418. if (railways.containsKey(args[1])) {
  419. railways.remove(args[1]);
  420. railways.put(args[1], false);
  421. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_46").replace("&n", args[1]));
  422. }
  423. else {
  424. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_24").replace("&n", args[1]));
  425. }
  426. }
  427. else {
  428. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_25"));
  429. }
  430. }
  431. }
  432. else if (args[0].equalsIgnoreCase("join")) {
  433. if (player.hasPermission("rlc.join")) {
  434. if (args.length == 2) {
  435. if (railways.containsKey(args[1])) {
  436. if (!(railways.get(args[1]) == true)) {
  437. Location joinLoc = railways_spawn.get(args[1]);
  438. if (railways_spawn.containsKey(args[1])) {
  439. railways_spawn_count.put(args[1], 1);
  440. }
  441. else {
  442. player.sendMessage(this.getConfig().getString("translation_44"));
  443. }
  444. if (railways_spawn_2.containsKey(args[1])) {
  445. Location changeLoc2 = railways_spawn_2.get(args[1]);
  446. joinLoc.setX(changeLoc2.getX());
  447. joinLoc.setY(changeLoc2.getY());
  448. joinLoc.setZ(changeLoc2.getZ());
  449. railways_spawn_count.put(args[1], 2);
  450. }
  451. else {
  452. player.sendMessage(this.getConfig().getString("translation_44"));
  453. }
  454. if (railways_spawn_3.containsKey(args[1])) {
  455. Location changeLoc3 = railways_spawn_3.get(args[1]);
  456. joinLoc.setX(changeLoc3.getX());
  457. joinLoc.setY(changeLoc3.getY());
  458. joinLoc.setZ(changeLoc3.getZ());
  459. railways_spawn_count.put(args[1], 3);
  460. }
  461. if (railways_spawn_4.containsKey(args[1])) {
  462. Location changeLoc4 = railways_spawn_4.get(args[1]);
  463. joinLoc.setX(changeLoc4.getX());
  464. joinLoc.setY(changeLoc4.getY());
  465. joinLoc.setZ(changeLoc4.getZ());
  466. railways_spawn_count.put(args[1], 4);
  467. }
  468. else {
  469. player.sendMessage(this.getConfig().getString("translation_44"));
  470. }
  471. if (railways_spawn_5.containsKey(args[1])) {
  472. Location changeLoc5 = railways_spawn_5.get(args[1]);
  473. joinLoc.setX(changeLoc5.getX());
  474. joinLoc.setY(changeLoc5.getY());
  475. joinLoc.setZ(changeLoc5.getZ());
  476. railways_spawn_count.put(args[1], 5);
  477. }
  478. else {
  479. player.sendMessage(this.getConfig().getString("translation_44"));
  480. }
  481. if (railways_spawn_6.containsKey(args[1])) {
  482. Location changeLoc6 = railways_spawn_6.get(args[1]);
  483. joinLoc.setX(changeLoc6.getX());
  484. joinLoc.setY(changeLoc6.getY());
  485. joinLoc.setZ(changeLoc6.getZ());
  486. railways_spawn_count.put(args[1], 6);
  487. }
  488. else {
  489. player.sendMessage(this.getConfig().getString("translation_44"));
  490. }
  491. player.getWorld().spawn(joinLoc, Minecart.class);
  492. player.teleport(joinLoc);
  493. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_26").replace("&n", args[1]));
  494. player.sendMessage("I ALT: " + railways_spawn_count.get(args[1]) + " -NICE IKK'?!");
  495. railways_players.put(player.getName(), args[1]);
  496. int countdown = 15;
  497. while (countdown != 0) {
  498. player.sendMessage(ChatColor.DARK_AQUA + this.getConfig().getString("translation_27") + ChatColor.RED + countdown);
  499. countdown--;
  500. try {
  501. Thread.sleep(1000);
  502. } catch (InterruptedException e) {
  503. e.printStackTrace();
  504. }
  505. if (countdown == 0) {
  506. player.sendMessage(ChatColor.YELLOW + this.getConfig().getString("translation_28"));
  507. railways.remove(args[1]);
  508. railways.put(args[1], true);
  509. }
  510. }
  511. }
  512. else {
  513. player.sendMessage(this.getConfig().getString("translation_29"));
  514. }
  515. }
  516. else {
  517. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_30").replace("&n", args[1]));
  518. }
  519. }
  520. else {
  521. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_31"));
  522. }
  523. }
  524. }
  525. else if (args[0].equalsIgnoreCase("list")) {
  526. if (player.hasPermission("rlc.list")) {
  527. if (args.length == 1) {
  528. if (!(railways.isEmpty())) {
  529. player.sendMessage("" + railways.size());
  530. }
  531. else {
  532. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_47"));
  533. }
  534. }
  535. else {
  536. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_33"));
  537. }
  538. }
  539. }
  540. else if (args[0].equalsIgnoreCase("shop")) {
  541. if (player.hasPermission("rlc.shop")) {
  542. if (args.length == 1) {
  543. player.sendMessage(ChatColor.AQUA + this.getConfig().getString("translation_32"));
  544. player.sendMessage(ChatColor.GRAY + "- Skriv '/c buy nitro' for at få din bil hurtigere!");
  545. player.sendMessage(ChatColor.GRAY + "- //ANDRE TING.. :O");
  546. }
  547. else {
  548. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_33"));
  549. }
  550. }
  551. }
  552. else if (args[0].equalsIgnoreCase("buy")) {
  553. if (player.hasPermission("rlc.buy")) {
  554. if (args.length == 2) {
  555. if (shop.containsKey(args[1])) {
  556. if (!(boost.containsKey(player.getName()))) {
  557. //DER SKAL ABEJDES PÅ AT TRÆKKE PENGE FRA KONTO
  558. boost.put(player.getName(), args[1]);
  559. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_34").replace("&n", args[1]));
  560. }
  561. else {
  562. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_35"));
  563. }
  564. }
  565. else {
  566. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_36").replace("&n", args[1]));
  567. }
  568. }
  569. else {
  570. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_37"));
  571. }
  572. }
  573. }
  574. else if (args[0].equalsIgnoreCase("add")) {
  575. if (player.hasPermission("rlc.add")) {
  576. if (args.length == 3) {
  577. if (!(shop.containsKey(args[1]))) {
  578. shop.put(args[1], args[2]);
  579. player.sendMessage(ChatColor.GREEN + this.getConfig().getString("translation_38").replace("&n", args[1]));
  580. }
  581. else {
  582. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_39").replace("&n", args[1]));
  583. }
  584. }
  585. else {
  586. player.sendMessage(ChatColor.RED + this.getConfig().getString("translation_40"));
  587. }
  588. }
  589. }
  590. }
  591. return false;
  592. }
  593.  
  594. @EventHandler
  595. public void onPlayerInteract(PlayerInteractEvent event) {
  596. Player player = event.getPlayer();
  597. if (player.getItemInHand().getTypeId() == 328 && event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
  598. if (player.hasPermission("rlc.create")) {
  599. Location loc = event.getClickedBlock().getLocation();
  600. loc.add(0, 1, 0);
  601. player.getWorld().spawn(loc, Minecart.class);
  602. }
  603. }
  604. }
  605. @EventHandler
  606. public void onVehicleUpdate(VehicleUpdateEvent event) {
  607. Entity passenger = event.getVehicle().getPassenger();
  608. if(!(passenger instanceof Player)) {
  609. return;
  610. }
  611. //FÅR BILEN TIL AT KØRER
  612. Player player = (Player) event.getVehicle().getPassenger();
  613. int Speed = 5;
  614. if (boost.containsKey(player.getName())) {
  615. if (boost.get(player.getName()) == "nitro") {
  616. //COMMING SOON!
  617. }
  618. }
  619. if(event.getVehicle() instanceof Minecart) {
  620. if(player.isInsideVehicle()) {
  621. Location newLoc = event.getVehicle().getLocation();
  622. Vector velocity = event.getVehicle().getPassenger().getVelocity();
  623. velocity.multiply(Speed);
  624. newLoc.add(new Vector(velocity.getX() * (double)Speed, 0.0D, velocity.getZ() * (double)Speed));
  625. event.getVehicle().teleport(newLoc);
  626. player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 0);
  627. }
  628. //DESTOERER BILEN HVIS DEN KØRER I VAND, ELLER LAVA!
  629. if(event.getVehicle().getLocation().subtract(0.0D, 1.0D, 0.0D).getBlock().isLiquid()) {
  630. event.getVehicle().eject();
  631. event.getVehicle().remove();
  632. //LUKKER BANEN
  633. railways_players.remove(player.getName());
  634. player.playEffect(player.getLocation(), Effect.EXTINGUISH, 0);
  635. player.sendMessage(this.getConfig().getString("translation_41"));
  636. }
  637. Location loc = event.getVehicle().getLocation().getBlock().getLocation();
  638.  
  639. //TJEKKER OM PLAYEREN ER PÅ EN WINNERLOC!
  640. if (railways_stop.containsValue(loc)) {
  641. if (railways_players.containsKey(player.getName())) {
  642. String railways_name = railways_players.get(player.getName());
  643. if (railways.get(railways_name) == true) {
  644. railways.remove(railways_name);
  645. railways.put(railways_name, false);
  646. Bukkit.broadcastMessage(ChatColor.AQUA + this.getConfig().getString("translation_42").replace("&rn", railways_name));
  647. player.sendMessage(ChatColor.DARK_GREEN + this.getConfig().getString("translation_43"));
  648. event.getVehicle().eject();
  649. event.getVehicle().remove();
  650. player.teleport(railways_finish.get(railways_name));
  651. }
  652. }
  653. }
  654. //'BUG' FIXES..
  655. Location bugLoc = event.getVehicle().getLocation();
  656. if (!(bugLoc.getBlock().getType() == Material.AIR)) {
  657. bugLoc.add(0, 1, 0);
  658. if (bugLoc.getBlock().getType() == Material.AIR) {
  659. Location fixloc = event.getVehicle().getLocation();
  660. fixloc.add(0, 1, 0);
  661. event.getVehicle().teleport(fixloc);
  662. }
  663. }
  664. }
  665. }
  666. @EventHandler
  667. public void onVehicleEntityCollision(VehicleEntityCollisionEvent event) {
  668. if (event.getVehicle() instanceof Minecart) {
  669. event.setCancelled(true);
  670. }
  671. }
  672. @EventHandler
  673. public void onVehicleBlockCollision(VehicleBlockCollisionEvent event) {
  674. if (event.getVehicle() instanceof Minecart) {
  675. Bukkit.broadcastMessage("Test..");
  676. event.getVehicle().setVelocity(new Vector(-1,-1,-1));
  677. }
  678. }
  679. @EventHandler
  680. public void onPlayerQuit(PlayerQuitEvent event) {
  681. railways_players.remove(event.getPlayer().getName());
  682. }
  683. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement