PageRenderTime 64ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/HungerCraft/src/me/dr_madman/hungercraft/HungerCraft.java

https://gitlab.com/vinnyjth/HungerCraft
Java | 897 lines | 774 code | 57 blank | 66 comment | 128 complexity | efe30b9979f6191517f81560a0139110 MD5 | raw file
  1. package me.dr_madman.hungercraft;
  2. import java.io.File;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Random;
  7. import java.util.logging.Logger;
  8. import org.bukkit.Bukkit;
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.GameMode;
  11. import org.bukkit.Location;
  12. import org.bukkit.World;
  13. import org.bukkit.WorldCreator;
  14. import org.bukkit.WorldType;
  15. import org.bukkit.World.Environment;
  16. import org.bukkit.block.Biome;
  17. import org.bukkit.command.Command;
  18. import org.bukkit.command.CommandExecutor;
  19. import org.bukkit.command.CommandSender;
  20. import org.bukkit.configuration.file.FileConfiguration;
  21. import org.bukkit.entity.Player;
  22. import org.bukkit.inventory.Inventory;
  23. import org.bukkit.inventory.PlayerInventory;
  24. import org.bukkit.plugin.PluginDescriptionFile;
  25. import org.bukkit.plugin.java.JavaPlugin;
  26. import org.bukkit.potion.PotionEffect;
  27. import org.bukkit.potion.PotionEffectType;
  28. import org.bukkit.util.Vector;
  29. import me.dr_madman.hungercraft.KitHandler;
  30. public class HungerCraft extends JavaPlugin implements CommandExecutor{
  31. @SuppressWarnings("unused")
  32. private static final Logger logger = Logger.getLogger("Minecraft");
  33. public static FileConfiguration cfg;
  34. public static HungerCraft plugin;
  35. public static PluginDescriptionFile plugdes;
  36. public CompassTracker compasstracker = new CompassTracker(this);
  37. public HungerListener hungerlistener = new HungerListener(this);
  38. public RandomTeleport randomteleport = new RandomTeleport(this);
  39. public WorldManagement worldmanagement = new WorldManagement(this);
  40. public TeamHandler teamhandler = new TeamHandler(this);
  41. public KitHandler kithandler = new KitHandler(this);
  42. public CompassTrackerUpdater compasstrackerupdater = new CompassTrackerUpdater(this);
  43. private int id;
  44. private int yes;
  45. private int no;
  46. public int tostart = 0;
  47. public int voted = 0;
  48. public boolean countdownactive = false;
  49. public String prefix = "[HC] " + ChatColor.ITALIC + "" + ChatColor.GREEN;
  50. public HashMap<Player, String> chosenkit = new HashMap<Player, String>();
  51. public HashMap<Player, String> chosenkitvip = new HashMap<Player, String>();
  52. private HashMap<Player, Boolean> hasvoted = new HashMap<Player, Boolean>();
  53. private HashMap<Player, Boolean> hasvotedteam = new HashMap<Player, Boolean>();
  54. public HashMap<Player, Boolean> isgm = new HashMap<Player, Boolean>();
  55. public HashMap<Integer, List<Player>> teams = new HashMap<Integer, List<Player>>();
  56. public Location getLocation(Player p, int i){
  57. int x = cfg.getInt(p.getWorld().getName() + "." + i + "." + "X");
  58. int y = cfg.getInt(p.getWorld().getName() + "." + i + "." + "Y");
  59. int z = cfg.getInt(p.getWorld().getName() + "." + i + "." + "Z");
  60. Location loc = new Location(p.getWorld(), x, y, z);
  61. return loc;
  62. }
  63. @Override
  64. public void onEnable(){
  65. plugdes = getDescription();
  66. System.out.println("PLUGDESC NAME: "+plugdes.getName());
  67. getServer().getPluginManager().registerEvents(hungerlistener, this);
  68. getServer().getPluginManager().registerEvents(compasstracker, this);
  69. checkFolder();
  70. clearTags();
  71. checkVIPFolder();
  72. cfg = getConfig();
  73. cfg.addDefault("isactive", false);
  74. cfg.addDefault("option.usespawnpoints", false);
  75. cfg.addDefault("option.spawnradius", 30);
  76. cfg.addDefault("option.arenasize", 500);
  77. cfg.addDefault("option.borderkill", true);
  78. cfg.addDefault("option.joinmessage", "Interested in VIP or Gamemaker? Type /buy");
  79. cfg.addDefault("option.teams", true);
  80. cfg.addDefault("participants", null);
  81. cfg.addDefault("leftgame", null);
  82. cfg.addDefault("nametag", null);
  83. cfg.addDefault("dead", null);
  84. cfg.addDefault("teamvote", null);
  85. cfg.addDefault("world", "world");
  86. cfg.addDefault("motd", "Game inactive");
  87. cfg.addDefault("option.timebetweenrounds", 300);
  88. cfg.addDefault("setup", false);
  89. cfg.addDefault("option.worldname", "arena1");
  90. cfg.addDefault("VIP", null);
  91. cfg.addDefault("option.owner", "Dr_MadMan");
  92. tostart = 0;
  93. voted = 0;
  94. hasvoted.clear();
  95. hasvotedteam.clear();
  96. yes = 0;
  97. no = 0;
  98. try {
  99. KitHandler.initKits();
  100. KitHandler.initVIP();
  101. } catch (Exception e) {
  102. // TODO Auto-generated catch block
  103. e.printStackTrace();
  104. }
  105. getConfig().options().copyDefaults(true);
  106. saveConfig();
  107. List<World> worlds = Bukkit.getServer().getWorlds();
  108. for (World world : worlds){
  109. world.setPVP(false);
  110. }
  111. if(!checkForWorld(getConfig().getString("option.worldname"))){
  112. generateWorld();
  113. }
  114. stopGameEndofRound();
  115. }
  116. @Override
  117. public void onDisable() {
  118. System.out.println(plugdes.getName() + " is now disabled.");
  119. CompassTrackerUpdater.stop();
  120. }
  121. public boolean checkForWorld(String world){
  122. List<World> worlds = getServer().getWorlds();
  123. World worldname = getServer().getWorld(world);
  124. if (worlds.contains(worldname)){
  125. return true;
  126. }
  127. else{
  128. return false;
  129. }
  130. }
  131. public void clearTags(){
  132. for (Player player: getServer().getOnlinePlayers()){
  133. String pname = player.getName();
  134. player.setPlayerListName(pname);
  135. }
  136. }
  137. /**public HashMap getKits(){
  138. HashMap<String, List<ItemStack>> kits = new HashMap<String, List<ItemStack>>();
  139. List<ItemStack> kitlist = getConfig().getConfigurationSection("kits.").getKeys(false)
  140. for (String key : getConfig().getConfigurationSection("kits.").getKeys(false)){
  141. kits.put(key, getConfig().getInt("kits." + key));
  142. }
  143. return kits;
  144. }
  145. */
  146. public void checkFolder(){
  147. File dir1 = getDataFolder();
  148. File dir = new File(dir1, "Classes");
  149. boolean exists = dir.exists();
  150. if(!exists){
  151. dir.mkdir();
  152. }
  153. }
  154. public void checkVIPFolder(){
  155. File dir1 = getDataFolder();
  156. File dir = new File(dir1, "VIP");
  157. boolean exists = dir.exists();
  158. if(!exists){
  159. dir.mkdir();
  160. }
  161. }
  162. public void generateWorld(){
  163. String worldname = getConfig().getString("option.worldname");
  164. String worldnameraw = worldname.substring(0, worldname.length()-1);
  165. int i = Integer.parseInt(worldname.substring(worldname.length()-1, worldname.length()));
  166. i++;
  167. String newworldname = worldnameraw + i;
  168. cfg.set("option.worldname", newworldname);
  169. saveConfig();
  170. final WorldCreator newworld = new WorldCreator(newworldname);
  171. Random randomGenerator = new Random();
  172. Long seed = randomGenerator.nextLong();
  173. newworld.type(WorldType.NORMAL);
  174. newworld.environment(Environment.NORMAL);
  175. newworld.generateStructures(true);
  176. newworld.seed(seed);
  177. Bukkit.getServer().createWorld(newworld);
  178. Bukkit.getServer().broadcastMessage("World created!");
  179. }
  180. /**public void initKits(){
  181. HashMap<String, List<ItemStack>> classes = new HashMap<String, List<ItemStack>>();
  182. List<ItemStack> archeritems = Arrays.asList(new ItemStack(Material.BOW, 1), new ItemStack(Material.ARROW, 16), new ItemStack(Material.COMPASS, 1));
  183. classes.put("archer", archeritems);
  184. List<ItemStack> mineritems = Arrays.asList(new ItemStack(Material.STONE_PICKAXE, 1), new ItemStack(Material.COMPASS, 1));
  185. classes.put("miner", mineritems);
  186. List<ItemStack> bakeritems = Arrays.asList(new ItemStack(Material.BREAD, 4), new ItemStack(Material.COMPASS, 1));
  187. classes.put("baker", bakeritems);
  188. }
  189. public void saveKit(HashMap<String, List<ItemStack>> classes){
  190. for (Map.Entry<String, List<ItemStack>> entry : classes.entrySet())
  191. {
  192. getConfig().set("kits." + entry.getKey(), entry.getValue());
  193. saveConfig();
  194. }
  195. }*/
  196. public static JavaPlugin getPlugin(){
  197. return plugin;
  198. }
  199. public void randomTeleport(){
  200. Player[] players = Bukkit.getServer().getOnlinePlayers();
  201. for (Player player : players){
  202. player.teleport(getServer().getWorld(getConfig().getString("option.worldname")).getSpawnLocation().add(new Vector(0,64,0)));
  203. }
  204. }
  205. public void countdown(final Player player){
  206. if (countdownactive == true){
  207. return;
  208. }
  209. countdownactive = true;
  210. this.id = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  211. int timebetweenrounds = cfg.getInt("option.timebetweenrounds")+10;
  212. public void run() {
  213. if(Bukkit.getServer().getOnlinePlayers().length <= 1){
  214. Bukkit.getServer().broadcastMessage(prefix + "Too few players to start the countdown:(");
  215. stopGameEndofRound();
  216. Bukkit.getScheduler().cancelTask(id);
  217. return;
  218. }
  219. if(getConfig().getBoolean("isactive")){
  220. Bukkit.getScheduler().cancelTask(id);
  221. }
  222. else {
  223. timebetweenrounds = timebetweenrounds - 10;
  224. Bukkit.getServer().broadcastMessage(prefix + "Round starts in " + timebetweenrounds + " seconds");
  225. cfg.set("motd", "Round starts in " + timebetweenrounds + " seconds");
  226. saveConfig();
  227. if (timebetweenrounds < 0){
  228. Bukkit.getScheduler().cancelTask(id);
  229. }
  230. if (timebetweenrounds == 0){
  231. countdownactive = false;
  232. startGame(player);
  233. Bukkit.getScheduler().cancelTask(id);
  234. }
  235. }
  236. }
  237. }, 1L, 200L);
  238. }
  239. public void setParticipants(){
  240. Player[] players = Bukkit.getOnlinePlayers();
  241. List<String> participants = new ArrayList<String>();
  242. for (Player player : players){
  243. String parname = player.getName();
  244. participants.add(parname);
  245. player.setHealth(20);
  246. player.setFoodLevel(20);
  247. Inventory inv = player.getInventory();
  248. inv.clear();
  249. player.setGameMode(GameMode.SURVIVAL);
  250. ((PlayerInventory) inv).setBoots(null);
  251. ((PlayerInventory) inv).setLeggings(null);
  252. ((PlayerInventory) inv).setChestplate(null);
  253. ((PlayerInventory) inv).setHelmet(null);
  254. show(player);
  255. player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 1200, 10));
  256. }
  257. cfg = getConfig();
  258. cfg.set("participants", participants);
  259. saveConfig();
  260. }
  261. public void startGame(Player sender){
  262. if(Bukkit.getServer().getOnlinePlayers().length < 2){
  263. Bukkit.getServer().broadcastMessage(prefix + "Too few players to start :(");
  264. return;
  265. }
  266. cfg = getConfig();
  267. cfg.set("isactive", true);
  268. voted = 0;
  269. tostart = 0;
  270. hasvoted.clear();
  271. hasvotedteam.clear();
  272. checkVotes();
  273. saveConfig();
  274. randomTeleport();
  275. if(getConfig().getBoolean("option.teams")){
  276. if(getConfig().getBoolean("teamvote")){
  277. teamhandler.initTeams();
  278. teamhandler.setTeamTags();
  279. }
  280. }
  281. sender.getWorld().setPVP(true);
  282. World world = sender.getWorld();
  283. world.setTime(0);
  284. setParticipants();
  285. Bukkit.getServer().broadcastMessage(prefix + "The Hunger Games have Begun!");
  286. if(getConfig().getBoolean("option.teams")){
  287. if(getConfig().getBoolean("teamvote")){
  288. teamhandler.initTeams();
  289. teamhandler.setTeamTags();
  290. this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  291. public void run() {
  292. tellTeams();
  293. }
  294. }, 60L);
  295. }
  296. }
  297. //brodcastInvincbility();
  298. setMOTD("Game in progress");
  299. for(Player player : Bukkit.getServer().getOnlinePlayers()){
  300. if (chosenkit.containsKey(player)){
  301. String i = chosenkit.get(player);
  302. try {
  303. KitHandler.getKit(player, i);
  304. } catch (Exception e) {
  305. // TODO Auto-generated catch block
  306. e.printStackTrace();
  307. }
  308. }
  309. if (chosenkitvip.containsKey(player)){
  310. String i = chosenkitvip.get(player);
  311. try {
  312. KitHandler.getKitVIP(player, i);
  313. } catch (Exception e) {
  314. // TODO Auto-generated catch block
  315. e.printStackTrace();
  316. }
  317. }
  318. }
  319. }
  320. public void checkVotes(){
  321. if(yes > no){
  322. getConfig().set("teamvote", true);
  323. saveConfig();
  324. return;
  325. }
  326. if(no > yes){
  327. getConfig().set("teamvote", false);
  328. saveConfig();
  329. return;
  330. }
  331. else{
  332. getConfig().set("teamvote", false);
  333. saveConfig();
  334. return;
  335. }
  336. }
  337. public void tellTeams(){
  338. for(Player player : getServer().getOnlinePlayers()){
  339. int team = teamGrabber(player);
  340. List<Player> players = teams.get(team);
  341. List<String> playersnames = new ArrayList<String>();
  342. for (Player p : players){
  343. playersnames.add(p.getName());
  344. }
  345. player.sendMessage(prefix + "Your team is: " + playersnames);
  346. }
  347. }
  348. public void clearList(String list){
  349. cfg = getConfig();
  350. cfg.set(list, null);
  351. saveConfig();
  352. }
  353. public void brodcastInvincbility(){
  354. this.id = this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  355. int times = 60;
  356. public void run() {
  357. Bukkit.getServer().broadcastMessage(prefix + times + " Seconds remain of invincibility");
  358. times = times -10;
  359. if (times == -10){
  360. Bukkit.getServer().broadcastMessage(prefix + "Invincibilty has worn off!");
  361. Bukkit.getScheduler().cancelTask(id);
  362. }
  363. }
  364. }, 1L, 200L);
  365. }
  366. public boolean checkForWater(World world){
  367. Location spawn = world.getSpawnLocation();
  368. int x = spawn.getBlockX();
  369. int y = spawn.getBlockY();
  370. Biome spawnbiome = world.getBiome(x, y);
  371. if (spawnbiome == Biome.OCEAN){
  372. return false;
  373. }
  374. else{
  375. return true;
  376. }
  377. }
  378. /**public void regenChunks(World world){
  379. int borderSize = cfg.getInt("option.arenasize");
  380. borderSize = (borderSize/16) + 10;
  381. for(int x = -borderSize; x != borderSize; x++){
  382. Bukkit.getServer().broadcastMessage(x + "x");
  383. for(int y = -borderSize; y != borderSize; y++){
  384. Chunk chunk = world.getChunkAt(x, y);
  385. if(chunk.isLoaded()){
  386. world.regenerateChunk(x, y);
  387. }
  388. }
  389. }
  390. }
  391. */
  392. public void stopGame(Player sender){
  393. cfg = getConfig();
  394. cfg.set("isactive", false);
  395. clearList("participants");
  396. clearList("leftgame");
  397. clearList("dead");
  398. saveConfig();
  399. teams.clear();
  400. sender.getWorld().setPVP(false);
  401. }
  402. public void stopGameEndofRound(){
  403. cfg = getConfig();
  404. cfg.set("setup", false);
  405. cfg.set("isactive", false);
  406. cfg.set("motd", "Game has not started yet");
  407. yes = 0;
  408. no = 0;
  409. clearList("participants");
  410. clearList("leftgame");
  411. clearList("dead");
  412. saveConfig();
  413. }
  414. /**public void addKit(String name, String item, int amount){
  415. HashMap<String, List<ItemStack>> classes = new HashMap<String, List<ItemStack>>();
  416. ItemStack itemstack = new ItemStack(Material.getMaterial(item.toUpperCase()), amount);
  417. List<ItemStack> list = Arrays.asList(itemstack);
  418. list.add(itemstack);
  419. classes.put(name,list);
  420. saveKit(classes);
  421. }
  422. */
  423. public List<String> getPars(){
  424. List<String> list = getConfig().getStringList("participants");
  425. return list;
  426. }
  427. public void setMOTD(String message){
  428. cfg.set("motd", message);
  429. saveConfig();
  430. }
  431. public void vanish(Player player){
  432. player.sendMessage(prefix + "You are now hidden");
  433. for (Player hidefrom :Bukkit.getServer().getOnlinePlayers()){
  434. hidefrom.hidePlayer(player);
  435. }
  436. }
  437. public void show(Player player){
  438. for (Player hidefrom :Bukkit.getServer().getOnlinePlayers()){
  439. hidefrom.showPlayer(player);
  440. }
  441. }
  442. public void setGM(Player player){
  443. vanish(player);
  444. player.setGameMode(GameMode.CREATIVE);
  445. List<String> list = getPars();
  446. String pname = player.getName();
  447. list.remove(pname);
  448. getConfig().set("participants", list);
  449. getConfig().set("dead", getConfig().getStringList("dead").add(player.getName()));
  450. saveConfig();
  451. }
  452. public void disableGM(Player player){
  453. show(player);
  454. player.setGameMode(GameMode.SURVIVAL);
  455. getConfig().set("participants", getConfig().getStringList("participants").add(player.getName()));
  456. getConfig().set("dead", getConfig().getStringList("dead").remove(player.getName()));
  457. saveConfig();
  458. }
  459. public void checkVotes(Player player){
  460. if(voted == tostart){
  461. getServer().broadcastMessage(prefix + "Enough votes have been recieved! Game is starting!");
  462. startGame(player);
  463. }
  464. else{
  465. int votesleft = tostart-voted;
  466. Bukkit.getServer().broadcastMessage(prefix + votesleft + " votes are needed to start the game");
  467. }
  468. }
  469. public boolean processVote(String vote, Player player){
  470. if(vote.equalsIgnoreCase("yes")){
  471. yes++;
  472. player.sendMessage(prefix + "You have voted yes!");
  473. getServer().broadcastMessage(prefix +"The votes for teammode are now " + yes + " for yes, and " + no + " for no");
  474. return true;
  475. }
  476. if(vote.equalsIgnoreCase("no")){
  477. no++;
  478. player.sendMessage(prefix + "You have voted no!");
  479. getServer().broadcastMessage(prefix +"The votes for teammode are now " + yes + " for yes, and " + no + " for no");
  480. return true;
  481. }
  482. else{
  483. player.sendMessage("You need to vote either yes or no!");
  484. return false;
  485. }
  486. }
  487. public int teamGrabber(Player player){
  488. String talkertag = player.getPlayerListName().substring(player.getPlayerListName().length() - 3, player.getPlayerListName().length());
  489. char talkerchar = talkertag.charAt(1);
  490. int team = Character.getNumericValue(talkerchar);
  491. return team;
  492. }
  493. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
  494. Player player = (Player) sender;
  495. if (cmd.getName().equalsIgnoreCase("teleport")){
  496. player.teleport(getServer().getWorld(getConfig().getString("worldname")).getSpawnLocation());
  497. }
  498. if(cmd.getName().equalsIgnoreCase("startgame")){
  499. if(player.isOp()){
  500. if(!getConfig().getBoolean("isactive")){
  501. countdown(player);
  502. return true;
  503. }
  504. else {
  505. player.sendMessage(prefix + "Game is already started!");
  506. }
  507. }
  508. else {
  509. player.sendMessage(prefix + "You must be an OP to start the game!");
  510. return true;
  511. }
  512. }
  513. if(cmd.getName().equalsIgnoreCase("forcestart")){
  514. if(player.isOp()){
  515. if(!getConfig().getBoolean("isactive")){
  516. startGame(player);
  517. return true;
  518. }
  519. else {
  520. player.sendMessage(prefix + "Game is already started!");
  521. }
  522. }
  523. else {
  524. player.sendMessage(prefix + "You must be an OP to start the game!");
  525. return true;
  526. }
  527. }
  528. if(cmd.getName().equalsIgnoreCase("stopgame")){
  529. if(player.isOp()){
  530. if(getConfig().getBoolean("isactive")){
  531. stopGameEndofRound();
  532. player.sendMessage(prefix + "Game has been stopped");
  533. return true;
  534. }
  535. else {
  536. player.sendMessage(prefix + "Game is already stopped!");
  537. }
  538. }
  539. else {
  540. player.sendMessage(prefix + "You must be an OP to start the game!");
  541. return true;
  542. }
  543. }
  544. if(cmd.getName().equalsIgnoreCase("setborder")){
  545. if(args[0] == null){
  546. return false;
  547. }
  548. int bordersize = Integer.parseInt(args[0]);
  549. getConfig().set("option.arenasize", bordersize);
  550. saveConfig();
  551. reloadConfig();
  552. player.sendMessage("Border has been set");
  553. return true;
  554. }
  555. if (cmd.getName().equalsIgnoreCase("kit")){
  556. if(args.length == 0){
  557. sender.sendMessage(prefix +"These are the kits " + KitHandler.listKits());
  558. return true;
  559. }
  560. if(args[0] == "list"){
  561. player.sendMessage(prefix +"These are the kits " + KitHandler.listKits());
  562. return true;
  563. }
  564. if (getConfig().getBoolean("isactive")){
  565. player.sendMessage(prefix +"Game is in progress!");
  566. return true;
  567. }
  568. if(KitHandler.listKits().contains(args[0])){
  569. try {
  570. chosenkit.remove(player);
  571. chosenkit.put(player, args[0]);
  572. player.sendMessage(prefix + args[0]+ " chosen");
  573. return true;
  574. } catch (Exception e) {
  575. // TODO Auto-generated catch block
  576. e.printStackTrace();
  577. player.sendMessage(prefix + args[0] + "was invalid!");
  578. return false;
  579. }
  580. }
  581. else {
  582. player.sendMessage(prefix + "These are the kits" + KitHandler.listKits());
  583. return true;
  584. }
  585. }
  586. if (cmd.getName().equalsIgnoreCase("addkit")){
  587. if(!player.isOp()){
  588. player.sendMessage(prefix + "You must be Op to add a kit");
  589. return true;
  590. }
  591. else {
  592. player.sendMessage(Integer.parseInt(args[2]) + "");
  593. try {
  594. KitHandler.addKit(args[0], args[1], Integer.parseInt(args[2]));
  595. } catch (Exception e) {
  596. // TODO Auto-generated catch block
  597. e.printStackTrace();
  598. }
  599. player.sendMessage(args[0] + " was added");
  600. return true;
  601. }
  602. }
  603. if (cmd.getName().equalsIgnoreCase("additem")){
  604. if(!player.isOp()){
  605. player.sendMessage(prefix + "You must be Op to add a kit");
  606. return true;
  607. }
  608. else {
  609. try {
  610. KitHandler.addKitItem(args[0], args[1], Integer.parseInt(args[2]));
  611. player.sendMessage(args[0] + " items were added");
  612. return true;
  613. } catch (Exception e) {
  614. // TODO Auto-generated catch block
  615. e.printStackTrace();
  616. }
  617. return false;
  618. }
  619. }
  620. if (cmd.getName().equalsIgnoreCase("setgm")){
  621. if(!player.isOp()){
  622. player.sendMessage(prefix + "You must be Op to set a player as gamemaker");
  623. return true;
  624. }
  625. else {
  626. setGM(getServer().getPlayer(args[0]));
  627. player.sendMessage(args[0] + "is now a GM");
  628. return true;
  629. }
  630. }
  631. if (cmd.getName().equalsIgnoreCase("vote")){
  632. if(hasvotedteam.containsKey(player)){
  633. if(hasvotedteam.get(player) == true){
  634. player.sendMessage(prefix + "You have already voted!");
  635. return true;
  636. }
  637. }
  638. if (args.length == 0){
  639. return false;
  640. }
  641. else{
  642. if (processVote(args[0], player)){
  643. hasvotedteam.put(player, true);
  644. return true;
  645. }
  646. else {
  647. return false;
  648. }
  649. }
  650. }
  651. if (cmd.getName().equalsIgnoreCase("votestart")){
  652. if(getServer().getOnlinePlayers().length <= 1){
  653. player.sendMessage(prefix + "You can't vote to start, not enough players");
  654. return true;
  655. }
  656. if(hasvoted.containsKey(player)){
  657. if(hasvoted.get(player) == true){
  658. player.sendMessage(prefix + "You have already voted!");
  659. return false;
  660. }
  661. }
  662. player.sendMessage(prefix + "You have voted to start");
  663. voted++;
  664. checkVotes(player);
  665. hasvoted.put(player, true);
  666. return true;
  667. }
  668. if (cmd.getName().equalsIgnoreCase("itemlist")){
  669. if(args.length == 0){
  670. return false;
  671. }
  672. else{
  673. try {
  674. KitHandler.getKit(player, args[0]);
  675. } catch (Exception e) {
  676. // TODO Auto-generated catch block
  677. e.printStackTrace();
  678. }
  679. }
  680. }
  681. if (cmd.getName().equalsIgnoreCase("addvip")){
  682. if(!player.isOp()){
  683. player.sendMessage(prefix + "You must be Op to add a VIP");
  684. return true;
  685. }
  686. if(args.length == 0){
  687. return false;
  688. }
  689. else {
  690. List<String> vips = getConfig().getStringList("VIP");
  691. Player vip = getServer().getOfflinePlayer(args[0]).getPlayer();
  692. vips.add(vip.getName());
  693. saveConfig();
  694. if(vip.isOnline()){
  695. vip.sendMessage(prefix + args[0] + " You are now a VIP! Use /vipkit to pick a vipkit");
  696. }
  697. player.sendMessage(prefix + " You have set " + args[0] + " as a vip");
  698. return true;
  699. }
  700. }
  701. if(cmd.getName().equalsIgnoreCase("info")){
  702. player.sendMessage(prefix + "++++++++++++ HungerCraft INFO ++++++++++++" );
  703. player.sendMessage(prefix + getConfig().getStringList("participants") + " are the players left in the game");
  704. player.sendMessage(prefix + "Plugin created by Dr_MadMan");
  705. player.sendMessage(prefix + "This server is owned by " + getConfig().getString("option.owner"));
  706. player.sendMessage(prefix + "Bugs? Report to @Dr_MadMan on twitter");
  707. }
  708. if(cmd.getName().equalsIgnoreCase("gm")){
  709. if(player.hasPermission("hc.gm") || player.isOp()){
  710. if(isgm.containsKey(player)){
  711. if(isgm.get(player)){
  712. disableGM(player);
  713. player.sendMessage(prefix + "You are no longer GM");
  714. isgm.put(player, false);
  715. return true;
  716. }
  717. else{
  718. setGM(player);
  719. isgm.put(player, true);
  720. player.sendMessage(prefix + " You are now a GM");
  721. }
  722. }
  723. else{
  724. setGM(player);
  725. isgm.put(player, true);
  726. player.sendMessage(prefix + " You are now a GM");
  727. }
  728. }
  729. }
  730. if(cmd.getName().equalsIgnoreCase("pm")){
  731. if(hungerlistener.checkActive()){
  732. if(getConfig().getBoolean("teamvote")){
  733. int team = teamGrabber(player);
  734. List<Player> playerlist = teams.get(team);
  735. String msg = "";
  736. for (int i = 0; i < args.length; i++) {
  737. msg += args[i] + " ";
  738. }
  739. for (Player p: playerlist){
  740. p.sendMessage(prefix + player.getName() + " says: " + msg );
  741. }
  742. return true;
  743. }
  744. }
  745. }
  746. if(cmd.getName().equalsIgnoreCase("track")){
  747. if(hungerlistener.checkActive()){
  748. if(getConfig().getBoolean("teamvote")){
  749. int team = teamGrabber(player);
  750. List<Player> playerlist = teams.get(team);
  751. playerlist.remove(player);
  752. if(playerlist.size() == 0){
  753. player.sendMessage(prefix + "Your buddy is dead!");
  754. return true;
  755. }
  756. Player tracked = playerlist.get(0);
  757. CompassTrackerUpdater.setWatcher(player, tracked);
  758. player.sendMessage(prefix + "You are now tracking " + tracked.getName());
  759. tracked.sendMessage(prefix + player.getName() + " is looking for you!");
  760. }
  761. return true;
  762. }
  763. }
  764. //+++++++++++++++++++++++++++++++++++VIP+++++++++++++++++++++++++++++++++++++++
  765. if (cmd.getName().equalsIgnoreCase("vipkit")){
  766. if(args.length == 0){
  767. sender.sendMessage(prefix +"These are the kits " + KitHandler.listVipKits());
  768. return true;
  769. }
  770. if(args[0] == "list"){
  771. player.sendMessage(prefix +"These are the kits " + KitHandler.listVipKits());
  772. return true;
  773. }
  774. if (getConfig().getBoolean("isactive")){
  775. player.sendMessage(prefix +"Game is in progress!");
  776. return true;
  777. }
  778. if(getConfig().getStringList("VIP").contains(player.getName()) || player.hasPermission("hc.vip")){
  779. if(KitHandler.listVipKits().contains(args[0])){
  780. try {
  781. chosenkitvip.remove(player);
  782. chosenkitvip.put(player, args[0]);
  783. player.sendMessage(prefix + args[0]+ " chosen");
  784. return true;
  785. } catch (Exception e) {
  786. // TODO Auto-generated catch block
  787. e.printStackTrace();
  788. player.sendMessage(prefix + args[0] + "was invalid!");
  789. return false;
  790. }
  791. }
  792. else {
  793. player.sendMessage(prefix + "These are the kits" + KitHandler.listVipKits());
  794. return true;
  795. }
  796. }
  797. }
  798. if (cmd.getName().equalsIgnoreCase("addvipkit")){
  799. if(!player.isOp()){
  800. player.sendMessage(prefix + "You must be Op to add a kit");
  801. return true;
  802. }
  803. else {
  804. player.sendMessage(Integer.parseInt(args[2]) + "");
  805. try {
  806. KitHandler.addVIPKit(args[0], args[1], Integer.parseInt(args[2]));
  807. } catch (Exception e) {
  808. // TODO Auto-generated catch block
  809. e.printStackTrace();
  810. }
  811. player.sendMessage(args[0] + " was added");
  812. return true;
  813. }
  814. }
  815. if (cmd.getName().equalsIgnoreCase("addvipitem")){
  816. if(!player.isOp()){
  817. player.sendMessage(prefix + "You must be Op to add a kit");
  818. return true;
  819. }
  820. else {
  821. try {
  822. KitHandler.addVIPKitItem(args[0], args[1], Integer.parseInt(args[2]));
  823. player.sendMessage(args[0] + " items were added");
  824. return true;
  825. } catch (Exception e) {
  826. // TODO Auto-generated catch block
  827. e.printStackTrace();
  828. }
  829. return false;
  830. }
  831. }
  832. return false;
  833. }
  834. }