Advertisement
Guest User

Untitled

a guest
Dec 31st, 2015
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.48 KB | None | 0 0
  1. package com.nibbitgames.nibbitgames.uhc;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Collection;
  6. import java.util.HashMap;
  7. import java.util.HashSet;
  8. import java.util.Hashtable;
  9. import java.util.List;
  10. import java.util.Map.Entry;
  11. import java.util.Random;
  12.  
  13. import org.bukkit.Bukkit;
  14. import org.bukkit.ChatColor;
  15. import org.bukkit.DyeColor;
  16. import org.bukkit.GameMode;
  17. import org.bukkit.Location;
  18. import org.bukkit.Material;
  19. import org.bukkit.OfflinePlayer;
  20. import org.bukkit.Sound;
  21. import org.bukkit.World;
  22. import org.bukkit.WorldCreator;
  23. import org.bukkit.block.Block;
  24. import org.bukkit.block.BlockFace;
  25. import org.bukkit.block.Chest;
  26. import org.bukkit.block.Sign;
  27. import org.bukkit.block.Skull;
  28. import org.bukkit.command.Command;
  29. import org.bukkit.command.CommandSender;
  30. import org.bukkit.command.ConsoleCommandSender;
  31. import org.bukkit.configuration.file.FileConfiguration;
  32. import org.bukkit.enchantments.Enchantment;
  33. import org.bukkit.entity.ArmorStand;
  34. import org.bukkit.entity.Arrow;
  35. import org.bukkit.entity.Damageable;
  36. import org.bukkit.entity.EnderDragon;
  37. import org.bukkit.entity.Entity;
  38. import org.bukkit.entity.EntityType;
  39. import org.bukkit.entity.Giant;
  40. import org.bukkit.entity.Guardian;
  41. import org.bukkit.entity.HumanEntity;
  42. import org.bukkit.entity.IronGolem;
  43. import org.bukkit.entity.Item;
  44. import org.bukkit.entity.LivingEntity;
  45. import org.bukkit.entity.Player;
  46. import org.bukkit.entity.Sheep;
  47. import org.bukkit.entity.Silverfish;
  48. import org.bukkit.entity.Slime;
  49. import org.bukkit.entity.Snowball;
  50. import org.bukkit.entity.Squid;
  51. import org.bukkit.entity.TNTPrimed;
  52. import org.bukkit.entity.ThrownPotion;
  53. import org.bukkit.event.EventHandler;
  54. import org.bukkit.event.Listener;
  55. import org.bukkit.event.block.Action;
  56. import org.bukkit.event.block.BlockBreakEvent;
  57. import org.bukkit.event.block.BlockPlaceEvent;
  58. import org.bukkit.event.block.SignChangeEvent;
  59. import org.bukkit.event.enchantment.EnchantItemEvent;
  60. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  61. import org.bukkit.event.entity.EntityDamageEvent;
  62. import org.bukkit.event.entity.EntityDeathEvent;
  63. import org.bukkit.event.entity.EntityExplodeEvent;
  64. import org.bukkit.event.entity.EntityInteractEvent;
  65. import org.bukkit.event.entity.PlayerDeathEvent;
  66. import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
  67. import org.bukkit.event.inventory.InventoryInteractEvent;
  68. import org.bukkit.event.player.PlayerInteractEntityEvent;
  69. import org.bukkit.event.player.PlayerInteractEvent;
  70. import org.bukkit.event.player.PlayerItemConsumeEvent;
  71. import org.bukkit.event.player.PlayerMoveEvent;
  72. import org.bukkit.event.player.PlayerQuitEvent;
  73. import org.bukkit.inventory.Inventory;
  74. import org.bukkit.inventory.ItemStack;
  75. import org.bukkit.inventory.ShapedRecipe;
  76. import org.bukkit.inventory.meta.ItemMeta;
  77. import org.bukkit.plugin.Plugin;
  78. import org.bukkit.plugin.PluginManager;
  79. import org.bukkit.plugin.java.JavaPlugin;
  80. import org.bukkit.potion.Potion;
  81. import org.bukkit.potion.PotionEffect;
  82. import org.bukkit.potion.PotionEffectType;
  83. import org.bukkit.scheduler.BukkitScheduler;
  84. import org.bukkit.scoreboard.DisplaySlot;
  85. import org.bukkit.scoreboard.Objective;
  86. import org.bukkit.scoreboard.Score;
  87. import org.bukkit.scoreboard.Scoreboard;
  88. import org.bukkit.scoreboard.ScoreboardManager;
  89. import org.bukkit.util.Vector;
  90.  
  91. import com.nibbitgames.nibbitgames.uhc.ParticleEffect.ParticleData;
  92.  
  93. public class Main extends JavaPlugin implements Listener{
  94.  
  95. @SuppressWarnings("unused")
  96. private Main plugin;
  97. ArrayList<String> players = new ArrayList<String>();
  98. ArrayList<String> team1 = new ArrayList<String>();
  99. ArrayList<String> team2 = new ArrayList<String>();
  100. ArrayList<String> spectator = new ArrayList<String>();
  101. public static HashMap<Location, Material> placed = new HashMap <Location, Material>();
  102. public static HashMap<Location, Material> broken = new HashMap <Location, Material>();
  103. public static HashMap<Location, Byte> brokenb = new HashMap <Location, Byte>();
  104.  
  105. World mainw = Bukkit.getWorld("UHC");
  106. Location midloc = new Location(mainw, 100, 100, 100);
  107.  
  108. private GameState gameState = GameState.WAITING; // default gamestate
  109. private UhcState uhcState = UhcState.GRACE; // default gamestate
  110.  
  111. public enum GameState {
  112. WAITING, // still waiting for players
  113. STARTING, // game is about to start, let's not accept any more players
  114. PLAYING; // the game has started
  115. }
  116. public enum UhcState {
  117. GRACE,
  118. NONGRACE;
  119. }
  120.  
  121. int canstart = 1;
  122. int cd = -15;
  123. int task1;
  124. int task2;
  125. int task3;
  126. int cd2 = -15;
  127. int chestmode = 0;
  128. int firstcoal = 1;
  129. int firstgold = 1;
  130. int firstredstone = 1;
  131. int firstdiamond = 1;
  132. int firstiron = 1;
  133. int firstlapis = 1;
  134. int firstemerald = 1;
  135. int firstenchant = 1;
  136.  
  137.  
  138. int sanik = 0;
  139.  
  140. public GameState getState() {
  141. return gameState;
  142. }
  143.  
  144. public void setState(GameState newState) {
  145. gameState = newState;
  146. }
  147.  
  148.  
  149. public void onEnable(){
  150. PluginManager pm = Bukkit.getServer().getPluginManager();
  151. pm.registerEvents(this, this);
  152. ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
  153. console.sendMessage(ChatColor.DARK_GRAY + "=-=-=-=-=-=-=-=-=-=-=-=-=");
  154. console.sendMessage(ChatColor.LIGHT_PURPLE + "NibbitUhc");
  155. console.sendMessage(ChatColor.LIGHT_PURPLE + "Version: 1.0");
  156. console.sendMessage(ChatColor.LIGHT_PURPLE + "Activated!");
  157. console.sendMessage(ChatColor.LIGHT_PURPLE + "Made by Norbu10");
  158. console.sendMessage(ChatColor.DARK_GRAY + "=-=-=-=-=-=-=-=-=-=-=-=-=");
  159. getConfig().options().copyDefaults(true);
  160. saveConfig();
  161.  
  162. ItemStack goldenhead = new ItemStack(Material.GOLDEN_APPLE, 1);
  163. ItemMeta goldenheadmeta = goldenhead.getItemMeta();
  164. goldenheadmeta.setDisplayName(ChatColor.LIGHT_PURPLE + "Power Apple");
  165. goldenheadmeta.addEnchant(Enchantment.DURABILITY, 1, true);
  166. goldenhead.setItemMeta(goldenheadmeta);
  167.  
  168. ShapedRecipe goldheadrecipe = new ShapedRecipe(goldenhead);
  169.  
  170. goldheadrecipe.shape(" % ","% %"," % ");
  171.  
  172. goldheadrecipe.setIngredient('%', Material.GOLDEN_APPLE);
  173.  
  174. getServer().addRecipe(goldheadrecipe);
  175.  
  176. startgame();
  177. graceperiod();
  178.  
  179. WorldCreator wc = new WorldCreator("UHC");
  180. World w = Bukkit.createWorld(wc);
  181. }
  182. public void onDisable(){
  183. ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
  184. console.sendMessage(ChatColor.DARK_GRAY + "=-=-=-=-=-=-=-=-=-=-=-=-=");
  185. console.sendMessage(ChatColor.LIGHT_PURPLE + "NibbitUhc");
  186. console.sendMessage(ChatColor.LIGHT_PURPLE + "Version: 1.0");
  187. console.sendMessage(ChatColor.LIGHT_PURPLE + "De-Activated!");
  188. console.sendMessage(ChatColor.LIGHT_PURPLE + "Made by Norbu10");
  189. console.sendMessage(ChatColor.DARK_GRAY + "=-=-=-=-=-=-=-=-=-=-=-=-=");
  190. saveConfig();
  191. }
  192.  
  193. @EventHandler
  194. public void blockplace(BlockPlaceEvent e){
  195. Player p = e.getPlayer();
  196. if(players.contains(p.getName())){
  197. if(p.getWorld().equals(mainw)){
  198. placed.put(e.getBlock().getLocation(), e.getBlock().getType());
  199. }
  200. }
  201. }
  202. @EventHandler
  203. public void blockbreak(BlockBreakEvent e){
  204. Player p = e.getPlayer();
  205. if(players.contains(p.getName())){
  206. if(p.getWorld().equals(mainw)){
  207. broken.put(e.getBlock().getLocation(), e.getBlock().getType());
  208. brokenb.put(e.getBlock().getLocation(), e.getBlock().getData());
  209. }
  210. }
  211. }
  212.  
  213. @EventHandler
  214. public void quit(PlayerQuitEvent e){
  215. if(players.contains(e.getPlayer().getName())){
  216. players.remove(e.getPlayer().getName());
  217. }
  218. if(spectator.contains(e.getPlayer().getName())){
  219. spectator.remove(e.getPlayer().getName());
  220. }
  221. }
  222.  
  223. @EventHandler
  224. public void signclick(PlayerInteractEvent e){
  225. Player p = e.getPlayer();
  226. Block b = e.getClickedBlock();
  227. if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
  228. if(b.getType() == Material.WALL_SIGN){
  229. Sign s = (Sign) b.getState();
  230. FileConfiguration con = getConfig();
  231.  
  232. Location uhclobby = new Location((World) Bukkit.getWorld((String) con.get("lobby.world")),(double) con.get("lobby.x"),(double) con.get("lobby.y"),(double) con.get("lobby.z"));
  233. uhclobby.setPitch((float) con.getDouble("lobby.pitch"));
  234. uhclobby.setPitch((float) con.getDouble("lobby.yaw"));
  235. if(s.getLine(1).contains("UltraHardcore")){
  236.  
  237. if(gameState.equals(GameState.WAITING)){
  238. if(!players.contains(p.getName())){
  239. players.add(p.getName());
  240. uhcbroadcast(p.getName() + " joined the game | " + players.size());
  241. p.getInventory().clear();
  242. p.getEquipment().clear();
  243. p.getInventory().setHelmet(null);
  244. p.getInventory().setChestplate(null);
  245. p.getInventory().setLeggings(null);
  246. p.getInventory().setBoots(null);
  247. p.setHealth(20);
  248. p.setFoodLevel(20);
  249. p.setGameMode(GameMode.ADVENTURE);
  250. p.teleport(uhclobby);
  251. if(players.size() == 2){
  252. TestEnough();
  253. }
  254. } else {
  255. p.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + "UHC" + ChatColor.WHITE + "]" + ChatColor.GOLD + " You are already in this game!");
  256. }
  257. }
  258. if(gameState.equals(GameState.STARTING)){
  259. if(!players.contains(p.getName())){
  260. players.add(p.getName());
  261. uhcbroadcast(p.getName() + " joined the game | " + players.size());
  262. p.getInventory().clear();
  263. p.getEquipment().clear();
  264. p.getInventory().setHelmet(null);
  265. p.getInventory().setChestplate(null);
  266. p.getInventory().setLeggings(null);
  267. p.getInventory().setBoots(null);
  268. p.setHealth(20);
  269. p.setFoodLevel(20);
  270. p.setGameMode(GameMode.ADVENTURE);
  271. p.teleport(uhclobby);
  272. }
  273. } else {
  274. p.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + "UHC" + ChatColor.WHITE + "]" + ChatColor.GOLD + " You are already in this game!");
  275. }
  276.  
  277. if(gameState.equals(GameState.PLAYING)){
  278. p.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + "UHC" + ChatColor.WHITE + "]" + ChatColor.GOLD + " This game is already active!");
  279. }
  280. }
  281. }
  282. }
  283. }
  284.  
  285.  
  286. public void uhcbroadcast(String message){
  287. for (String pl : players){
  288. Player pla = Bukkit.getPlayer(pl);
  289. pla.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + "UHC" + ChatColor.WHITE + "]" + ChatColor.GOLD + " " + message);
  290. }
  291. for (String pl : spectator){
  292. Player pla = Bukkit.getPlayer(pl);
  293. pla.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + "UHC" + ChatColor.WHITE + "]" + ChatColor.GOLD + " " + message);
  294. }
  295. }
  296.  
  297. @Override
  298. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
  299. if(sender instanceof Player){
  300. Player p = (Player) sender;
  301. if(commandLabel.equalsIgnoreCase("nibbituhc")){
  302. if(args[0].equalsIgnoreCase("join")){
  303. FileConfiguration con = getConfig();
  304.  
  305. Location uhclobby = new Location((World) Bukkit.getWorld((String) con.get("lobby.world")),(double) con.get("lobby.x"),(double) con.get("lobby.y"),(double) con.get("lobby.z"));
  306. uhclobby.setPitch((float) con.getDouble("lobby.pitch"));
  307. uhclobby.setPitch((float) con.getDouble("lobby.yaw"));
  308.  
  309. Location uhcspawn = new Location((World) Bukkit.getWorld((String) con.get("spawn.world")),(double) con.get("spawn.x"),(double) con.get("spawn.y"),(double) con.get("spawn.z"));
  310. uhcspawn.setPitch((float) con.getDouble("spawn.pitch"));
  311. uhcspawn.setPitch((float) con.getDouble("spawn.yaw"));
  312.  
  313. if(gameState.equals(GameState.STARTING)){
  314. if(players.contains(p.getName())){
  315. players.remove(p.getName());
  316. uhcbroadcast(p.getName() + " left the game | " + players.size());
  317. p.setGameMode(GameMode.ADVENTURE);
  318. p.teleport(uhcspawn);
  319. } else {
  320. players.add(p.getName());
  321. uhcbroadcast(p.getName() + " joined the game | " + players.size());
  322. p.setGameMode(GameMode.ADVENTURE);
  323. p.getInventory().clear();
  324. p.getEquipment().clear();
  325. p.getInventory().setHelmet(null);
  326. p.getInventory().setChestplate(null);
  327. p.getInventory().setLeggings(null);
  328. p.getInventory().setBoots(null);
  329. p.setHealth(20);
  330. p.setFoodLevel(20);
  331. p.teleport(uhclobby);
  332. }
  333. } else if(gameState.equals(GameState.WAITING)){
  334. if(players.contains(p.getName())){
  335. players.remove(p.getName());
  336. p.teleport(uhcspawn);
  337. uhcbroadcast(p.getName() + " left the game | " + players.size());
  338. p.setGameMode(GameMode.ADVENTURE);
  339. } else {
  340. players.add(p.getName());
  341. players.add(p.getName());//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  342. uhcbroadcast(p.getName() + " joined the game | " + players.size());
  343. p.setGameMode(GameMode.ADVENTURE);
  344. p.getInventory().clear();
  345. p.getEquipment().clear();
  346. p.getInventory().setHelmet(null);
  347. p.getInventory().setChestplate(null);
  348. p.getInventory().setLeggings(null);
  349. p.getInventory().setBoots(null);
  350. p.setHealth(20);
  351. p.setFoodLevel(20);
  352. p.teleport(uhclobby);
  353. if(players.size() == 2){
  354. TestEnough();
  355. }
  356. }
  357. }
  358. } else if (args[0].equalsIgnoreCase("restore")){
  359. restoreBlocks();
  360. } else if (args[0].equalsIgnoreCase("mid")){
  361. ChooseMid();
  362. } else if (args[0].equalsIgnoreCase("setspawn")){
  363. FileConfiguration con = getConfig();
  364. con.set("spawn.x", p.getLocation().getX());
  365. con.set("spawn.y", p.getLocation().getY());
  366. con.set("spawn.z", p.getLocation().getZ());
  367. con.set("spawn.yaw", p.getLocation().getYaw());
  368. con.set("spawn.pitch", p.getLocation().getPitch());
  369. con.set("spawn.world", p.getLocation().getWorld().getName());
  370. p.sendMessage("spawn set");
  371. saveConfig();
  372. } else if (args[0].equalsIgnoreCase("setlobby")){
  373. FileConfiguration con = getConfig();
  374. con.set("lobby.x", p.getLocation().getX());
  375. con.set("lobby.y", p.getLocation().getY());
  376. con.set("lobby.z", p.getLocation().getZ());
  377. con.set("lobby.yaw", p.getLocation().getYaw());
  378. con.set("lobby.pitch", p.getLocation().getPitch());
  379. con.set("lobby.world", p.getLocation().getWorld().getName());
  380. p.sendMessage("lobby set");
  381. saveConfig();
  382. } else if(args[0].equalsIgnoreCase("Giant1")){
  383. Giant mob = p.getWorld().spawn(p.getLocation(), Giant.class);
  384. mob.setRemoveWhenFarAway(false);
  385. mob.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 9999));
  386. mob.getEquipment().setItemInHand(new ItemStack(Material.GOLDEN_APPLE, 1));
  387. mob.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 9999));
  388. Location enderloc = p.getLocation();
  389. enderloc.setPitch(p.getLocation().getPitch());
  390. enderloc.setYaw(p.getLocation().getPitch());
  391. mob.teleport(enderloc);
  392. mob.setCustomName("NPC");
  393. mob.setCustomNameVisible(false);
  394. } else if(args[0].equalsIgnoreCase("Enderdragon1")){
  395. EnderDragon mob = p.getWorld().spawn(p.getLocation(), EnderDragon.class);
  396. mob.setRemoveWhenFarAway(false);
  397. mob.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 9999));
  398. mob.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 9999));
  399. Location enderloc = p.getLocation();
  400. enderloc.setPitch(p.getLocation().getPitch());
  401. enderloc.setYaw(p.getLocation().getPitch());
  402. mob.teleport(enderloc);
  403. } else if(args[0].equalsIgnoreCase("uhchelp")){
  404. ArmorStand ar = p.getWorld().spawn(p.getLocation(), ArmorStand.class);
  405. ar.setRemoveWhenFarAway(false);
  406. ar.setCustomName(ChatColor.WHITE + "[" + ChatColor.YELLOW + "Welcome to UHC!" + ChatColor.WHITE + "]");
  407. ar.setCustomNameVisible(true);
  408. ar.setVisible(false);
  409. } else if(args[0].equalsIgnoreCase("uhchelpa")){
  410. ArmorStand ar = p.getWorld().spawn(p.getLocation(), ArmorStand.class);
  411. ar.setRemoveWhenFarAway(false);
  412. ar.setCustomName(ChatColor.WHITE + "[" + ChatColor.YELLOW + "How to craft a " + ChatColor.LIGHT_PURPLE + "Power Apple" + ChatColor.WHITE + "]");
  413. ar.setCustomNameVisible(true);
  414. ar.setVisible(false);
  415. } else if(args[0].equalsIgnoreCase("sanik")){
  416. if(sanik == 1){
  417. sanik = 0;
  418. Bukkit.broadcastMessage(ChatColor.BLUE + p.getName() + " has de-activated Sanik mode for UHC! Gotta go slow :(");
  419. for(String pla : players){
  420. Player po = Bukkit.getPlayer(pla);
  421. po.removePotionEffect(PotionEffectType.SPEED);
  422. po.removePotionEffect(PotionEffectType.FAST_DIGGING);
  423. }
  424. } else {
  425. sanik = 1;
  426. Bukkit.broadcastMessage(ChatColor.BLUE + p.getName() + " has activated Sanik mode for UHC! Gotta go fast!");
  427. for(Player plal : Bukkit.getOnlinePlayers()){
  428. plal.playSound(plal.getLocation(), Sound.DRINK, 10, 10);
  429. plal.playSound(plal.getLocation(), Sound.DRINK, 10, 10);
  430. plal.playSound(plal.getLocation(), Sound.DRINK, 10, 10);
  431. plal.playSound(plal.getLocation(), Sound.DRINK, 10, 10);
  432. plal.playSound(plal.getLocation(), Sound.DRINK, 10, 10);
  433. plal.playSound(plal.getLocation(), Sound.DRINK, 10, 10);
  434. plal.playSound(plal.getLocation(), Sound.DRINK, 10, 10);
  435. plal.playSound(plal.getLocation(), Sound.DRINK, 10, 10);
  436. plal.playSound(plal.getLocation(), Sound.VILLAGER_YES, 10, 10);
  437. plal.playSound(plal.getLocation(), Sound.VILLAGER_YES, 10, 10);
  438. plal.playSound(plal.getLocation(), Sound.VILLAGER_YES, 10, 10);
  439. plal.playSound(plal.getLocation(), Sound.VILLAGER_YES, 10, 10);
  440. plal.playSound(plal.getLocation(), Sound.VILLAGER_YES, 10, 10);
  441. }
  442. for(String pla : players){
  443. Player po = Bukkit.getPlayer(pla);
  444. po.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, Integer.MAX_VALUE, 5));
  445. po.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 10));
  446. }
  447. }
  448. } else if(args[0].equalsIgnoreCase("tier3")){
  449. p.getLocation().getBlock().setType(Material.CHEST);
  450. chestTier3(p.getLocation().getBlock());
  451. } else if(args[0].equalsIgnoreCase("tier2")){
  452. p.getLocation().getBlock().setType(Material.CHEST);
  453. chestTier2(p.getLocation().getBlock());
  454. } else if(args[0].equalsIgnoreCase("tier1")){
  455. p.getLocation().getBlock().setType(Material.CHEST);
  456. chestTier1(p.getLocation().getBlock());
  457. } else if(args[0].equalsIgnoreCase("trap1")){
  458. p.getLocation().getBlock().setType(Material.AIR);
  459. Trap1(p.getLocation().getBlock(), p);
  460. } else if(args[0].equalsIgnoreCase("chests")){
  461. if(chestmode == 0){
  462. chestmode = 1;
  463. uhcbroadcast("Chest mode! Destroy as many blocks as you can to get treasure!");
  464. uhcsound(Sound.ZOMBIE_WOODBREAK);
  465. } else {
  466. chestmode = 0;
  467. uhcbroadcast("Default mode! No treasure chests!");
  468. uhcsound(Sound.ENDERMAN_DEATH);
  469. }
  470. }
  471. }
  472. }
  473. return false;
  474. }
  475. public void restoreBlocks(){
  476. for (Entry<Location, Material> plac : placed.entrySet()) {
  477. Location loc = plac.getKey();
  478. if(!loc.getBlock().getType().equals(Material.AIR)){
  479. loc.getBlock().setType(Material.AIR);
  480. }
  481. }
  482. for (Entry<Location, Material> bre : broken.entrySet()) {
  483. Location loc = bre.getKey();
  484. loc.getBlock().setType(bre.getValue());
  485. }
  486. for (Entry<Location, Byte> breb : brokenb.entrySet()) {
  487. Location loc = breb.getKey();
  488. loc.getBlock().setData(breb.getValue());
  489. }
  490. for(Entity i : mainw.getEntities()){
  491. if(i instanceof Item){
  492. i.remove();
  493. }
  494. }
  495. for (Entry<Location, Material> plac : placed.entrySet()) {
  496. Location loc = plac.getKey();
  497. if(!loc.getBlock().getType().equals(Material.AIR)){
  498. loc.getBlock().setType(Material.AIR);
  499. }
  500. }
  501. }
  502. public void ChooseMid(){
  503.  
  504. cd2 = 900;
  505. setState(GameState.PLAYING);
  506. Random randomx = new Random();
  507. int randommx = randomx.nextInt() % 99999;
  508. Random randomz = new Random();
  509. int randommz = randomz.nextInt() % 99999;
  510. Location loc = new Location(mainw, randommx, 0, randommz);
  511. int highesty = mainw.getHighestBlockYAt(loc);
  512. loc.setY(highesty);
  513. for (int count = 0; count < 100; count++) {
  514. mainw.getWorldBorder().setCenter(loc);
  515. mainw.getWorldBorder().setSize(700);
  516. }
  517. Block b9 = loc.getBlock().getRelative(BlockFace.UP);
  518. Block b10 = loc.getBlock().getRelative(BlockFace.UP).getRelative(BlockFace.UP);
  519. Block b11 = loc.getBlock().getRelative(BlockFace.UP).getRelative(BlockFace.UP).getRelative(BlockFace.UP);
  520. Block b = loc.getBlock();
  521. Block b1 = loc.getBlock().getRelative(BlockFace.NORTH);
  522. Block b2 = loc.getBlock().getRelative(BlockFace.EAST);
  523. Block b3 = loc.getBlock().getRelative(BlockFace.SOUTH);
  524. Block b4 = loc.getBlock().getRelative(BlockFace.WEST);
  525. Block b5 = loc.getBlock().getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST);
  526. Block b6 = loc.getBlock().getRelative(BlockFace.EAST).getRelative(BlockFace.SOUTH);
  527. Block b7 = loc.getBlock().getRelative(BlockFace.SOUTH).getRelative(BlockFace.WEST);
  528. Block b8 = loc.getBlock().getRelative(BlockFace.WEST).getRelative(BlockFace.NORTH);
  529. b10.setType(Material.GLASS);
  530. b11.setType(Material.GLASS);
  531. b10.setTypeIdAndData(Material.STAINED_GLASS.getId(), DyeColor.YELLOW.getWoolData(), true);
  532. b11.setTypeIdAndData(Material.STAINED_GLASS.getId(), DyeColor.ORANGE.getWoolData(), true);
  533. b9.setType(Material.BEACON);
  534. b.setType(Material.IRON_BLOCK);
  535. b1.setType(Material.IRON_BLOCK);
  536. b2.setType(Material.IRON_BLOCK);
  537. b3.setType(Material.IRON_BLOCK);
  538. b4.setType(Material.IRON_BLOCK);
  539. b5.setType(Material.IRON_BLOCK);
  540. b6.setType(Material.IRON_BLOCK);
  541. b7.setType(Material.IRON_BLOCK);
  542. b8.setType(Material.IRON_BLOCK);
  543. placed.put(b9.getLocation(), Material.BEACON);
  544. placed.put(b.getLocation(), Material.IRON_BLOCK);
  545. placed.put(b1.getLocation(), Material.IRON_BLOCK);
  546. placed.put(b2.getLocation(), Material.IRON_BLOCK);
  547. placed.put(b3.getLocation(), Material.IRON_BLOCK);
  548. placed.put(b4.getLocation(), Material.IRON_BLOCK);
  549. placed.put(b5.getLocation(), Material.IRON_BLOCK);
  550. placed.put(b6.getLocation(), Material.IRON_BLOCK);
  551. placed.put(b7.getLocation(), Material.IRON_BLOCK);
  552. placed.put(b8.getLocation(), Material.IRON_BLOCK);
  553. placed.put(b10.getLocation(), Material.GLASS);
  554. placed.put(b11.getLocation(), Material.GLASS);
  555. Location Team1Loc = new Location(loc.getWorld(), loc.getX()-349, loc.getY(), loc.getZ()-349);
  556. Team1Loc.setY(Team1Loc.getWorld().getHighestBlockYAt(Team1Loc));
  557. Team1Loc.getBlock().getRelative(BlockFace.DOWN).setType(Material.BEDROCK);
  558. Location Team2Loc = new Location(loc.getWorld(), loc.getX()+349, loc.getY(), loc.getZ()+349);
  559. Team2Loc.setY(Team2Loc.getWorld().getHighestBlockYAt(Team2Loc));
  560. Team2Loc.getBlock().getRelative(BlockFace.DOWN).setType(Material.BEDROCK);
  561. Block bedrock1 = Team2Loc.getBlock().getRelative(BlockFace.DOWN);
  562. Block bedrock2 = Team1Loc.getBlock().getRelative(BlockFace.DOWN);
  563. uhcbroadcast("The beacon is at : " + loc.getX() + "," + loc.getY() + "," + loc.getZ() + "!");
  564.  
  565. midloc = loc;
  566.  
  567. placed.put(bedrock1.getLocation(), Material.BEDROCK);
  568. placed.put(bedrock2.getLocation(), Material.BEDROCK);
  569. int divide = 1;
  570. Team2Loc.setY(100);
  571. Team1Loc.setY(100);
  572. for (String pl : players){
  573. Player pla = Bukkit.getPlayer(pl);
  574. if(divide == 1){
  575. uhcbroadcast(pla.getName() + " joined team 1");
  576. if(!pla.getWorld().equals(mainw)){
  577. pla.teleport(mainw.getSpawnLocation());
  578. pla.setGameMode(GameMode.SURVIVAL);
  579. }
  580. pla.teleport(Team1Loc);
  581. divide--;
  582. } else {
  583. uhcbroadcast(pla.getName() + " joined team 2");
  584. if(!pla.getWorld().equals(mainw)){
  585. pla.teleport(mainw.getSpawnLocation());
  586. pla.setGameMode(GameMode.SURVIVAL);
  587. }
  588. pla.teleport(Team2Loc);
  589. divide++;
  590. }
  591. }
  592. }
  593. @EventHandler
  594. public void leave(PlayerQuitEvent e){
  595. Player p = e.getPlayer();
  596. DeathPath(p);
  597. }
  598. public void TestEnough(){
  599. if(players.size() == 2){
  600. if(gameState.equals(gameState.WAITING)){
  601. setState(GameState.STARTING);
  602. cd = 30;
  603. }
  604. } else {
  605. uhcbroadcast("Not enough players!");
  606. }
  607. }
  608. @EventHandler
  609. public void playerDamage(PlayerDeathEvent e){
  610. Player p = e.getEntity();
  611. p.setHealth(20);
  612. if(players.contains(p.getName())){
  613. e.setDeathMessage("");
  614. uhcbroadcast(e.getDeathMessage());
  615. p.setGameMode(GameMode.SPECTATOR);
  616. DeathPath(p);
  617. }
  618. }
  619. public void startgame() {
  620. task1 = getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) this, new Runnable() {
  621. @Override
  622. public void run(){
  623. if(!(cd == -15)){
  624. if(cd == 0){
  625. if(canstart == 1){
  626. if(players.size() > 1){
  627. if(sanik == 1){
  628. for(String pla : players){
  629. Player po = Bukkit.getPlayer(pla);
  630. po.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, Integer.MAX_VALUE, 5));
  631. po.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 10));
  632. uhcbroadcast(ChatColor.BLUE + "Sanik mode! GOTTA GO FAAAST :D");
  633. }
  634. }
  635. firstcoal = 1;
  636. firstgold = 1;
  637. firstredstone = 1;
  638. firstdiamond = 1;
  639. firstiron = 1;
  640. firstemerald = 1;
  641. firstlapis = 1;
  642. firstenchant = 1;
  643. for(String play : players){
  644. Player playe = Bukkit.getPlayer(play);
  645. playe.setHealth(20);
  646. playe.setFoodLevel(20);
  647. }
  648. uhcbroadcast("The game has started! Fall damage is disabled in the grace period!"); //<-------------------------------------------------------------()
  649. if(chestmode == 0){
  650. uhcbroadcast("Chest mode! Destroy as many blocks as you can to get treasure!");
  651. uhcsound(Sound.ZOMBIE_WOODBREAK);
  652. } else {
  653. uhcbroadcast("Default mode! No treasure chests!");
  654. uhcsound(Sound.ENDERMAN_DEATH);
  655. }
  656. uhcState = UhcState.GRACE;
  657. ChooseMid();
  658. cd2 = 900;
  659. cd = -15;
  660. canstart = 0;
  661. ScoreboardManager manager = Bukkit.getScoreboardManager();
  662. Scoreboard board = manager.getNewScoreboard();
  663. Objective objective = board.registerNewObjective("showhealth", "health");
  664. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
  665. objective.setDisplayName("/ 20");
  666. for(Player online : Bukkit.getOnlinePlayers()){
  667. if(players.contains(online.getName())){
  668. online.setScoreboard(board);
  669. online.setHealth(online.getHealth()); //Update their health
  670. }
  671. }
  672.  
  673.  
  674. } else {
  675. cd = -15;
  676. }
  677. } else {
  678. }
  679. } else if(cd < 6){
  680. uhcbroadcast("Starting in " + cd + " seconds!"); //<-------------------------------------------------------------()
  681. uhcsound(Sound.NOTE_PLING);
  682. } else if(cd == 1){
  683. uhcbroadcast("Starting in " + cd + " second!"); //<-------------------------------------------------------------()
  684. uhcsound(Sound.NOTE_PLING);
  685. } else if(cd == 30){
  686. uhcbroadcast("Starting in " + cd + " seconds!"); //<-------------------------------------------------------------()
  687. uhcsound(Sound.NOTE_PLING);
  688. }
  689. for (String pl : players){
  690. Player pla = Bukkit.getPlayer(pl);
  691. pla.setLevel(cd);
  692. }
  693. if(cd > 0){
  694. cd--;
  695. }
  696. }
  697. showUHCScoreboard();
  698. }
  699. },0L, 20L); //Bukkit.getScheduler().cancelTask(task1);
  700. }
  701. public void graceperiod() {
  702. task2 = getServer().getScheduler().scheduleSyncRepeatingTask((Plugin) this, new Runnable() {
  703. @Override
  704. public void run(){
  705. if(!(cd2 == -15)){
  706. if(cd2 == 0){
  707. uhcState = UhcState.NONGRACE;
  708. uhcbroadcast("Graceperiod is over! The border is shrinking!");
  709. uhcsound(Sound.WITHER_DEATH);
  710. for (int count = 0; count < 100; count++) {
  711. mainw.getWorldBorder().setSize(700);
  712. mainw.getWorldBorder().setSize(40, 1800);
  713. cd2 = -15;
  714. }
  715. } else if(cd2 < 6){
  716. uhcbroadcast("Grace period ends in " + cd2 + " seconds!"); //<-------------------------------------------------------------()
  717. uhcsound(Sound.NOTE_PLING);
  718. } else if(cd2 == 1){
  719. uhcbroadcast("Grace period ends in " + cd2 + " second!"); //<-------------------------------------------------------------()
  720. uhcsound(Sound.NOTE_PLING);
  721. } else if(cd2 == 60){
  722. uhcbroadcast("Grace period ends in 1 minute!"); //<-------------------------------------------------------------()
  723. uhcsound(Sound.NOTE_PLING);
  724. } else if(cd2 == 90){
  725. uhcbroadcast("Grace period ends in 1.5 minutes!"); //<-------------------------------------------------------------()
  726. uhcsound(Sound.NOTE_PLING);
  727. } else if(cd2 == 300){
  728. uhcbroadcast("Grace period ends in 5 minutes!"); //<-------------------------------------------------------------()
  729. uhcsound(Sound.NOTE_PLING);
  730. } else if(cd2 == 600){
  731. uhcbroadcast("Grace period ends in 10 minutes!"); //<-------------------------------------------------------------()
  732. uhcsound(Sound.NOTE_PLING);
  733. } else if(cd2 == 900){
  734. uhcbroadcast("Grace period has started! it will end in 15 minutes!"); //<-------------------------------------------------------------()
  735. uhcsound(Sound.WITHER_SPAWN);
  736. }
  737. for (String pl : players){
  738. Player pla = Bukkit.getPlayer(pl);
  739. pla.setLevel(cd2);
  740. }
  741. if(cd2 > 0){
  742. cd2--;
  743. }
  744. }
  745. showUHCScoreboard();
  746. }
  747. },0L, 20L); //Bukkit.getScheduler().cancelTask(task1);
  748. }
  749.  
  750. @EventHandler
  751. public void NoTeamKill(EntityDamageByEntityEvent e){
  752. if(e.getEntity() instanceof Player){
  753. if(players.contains(e.getEntity().getName())){
  754. if(e.getDamager() instanceof Player){
  755. Player p = (Player) e.getEntity();
  756. Player da = (Player) e.getDamager();
  757. if(team1.contains(p.getName())){
  758. if(team1.contains(da.getName())){
  759. e.setCancelled(true);
  760. da.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + "UHC" + ChatColor.WHITE + "]" + ChatColor.GOLD + "You cannot hit your team members!");
  761. }
  762. }
  763. if(team2.contains(p.getName())){
  764. if(team2.contains(da.getName())){
  765. e.setCancelled(true);
  766. da.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + "UHC" + ChatColor.WHITE + "]" + ChatColor.GOLD + "You cannot hit your team members!");
  767. }
  768. }
  769. if(uhcState.equals(UhcState.GRACE)){
  770. e.setCancelled(true);
  771. da.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + "UHC" + ChatColor.WHITE + "]" + ChatColor.GOLD + "You cannot hit other players in grace period!");
  772. }
  773. }
  774. }
  775. }
  776. }
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783. @EventHandler
  784. public void AutoBake(EntityDeathEvent e){
  785. if(e.getEntity().getWorld().equals(mainw)){
  786. List<ItemStack> drops = e.getDrops();
  787. for(ItemStack i : drops){
  788. if(i.getType().equals(Material.MUTTON)){
  789. i.setType(Material.COOKED_MUTTON);
  790. ParticleEffect.FLAME.display(1, 1, 1, 0, 100, e.getEntity().getLocation(), 6);
  791. }
  792. if(i.getType().equals(Material.RAW_BEEF)){
  793. i.setType(Material.COOKED_BEEF);
  794. ParticleEffect.FLAME.display(1, 1, 1, 0, 100, e.getEntity().getLocation(), 6);
  795. }
  796. if(i.getType().equals(Material.PORK)){
  797. i.setType(Material.GRILLED_PORK);
  798. ParticleEffect.FLAME.display(1, 1, 1, 0, 100, e.getEntity().getLocation(), 6);
  799. }
  800. if(i.getType().equals(Material.RAW_CHICKEN)){
  801. i.setType(Material.COOKED_CHICKEN);
  802. ParticleEffect.FLAME.display(1, 1, 1, 0, 100, e.getEntity().getLocation(), 6);
  803. }
  804. if(i.getType().equals(Material.RABBIT)){
  805. i.setType(Material.COOKED_RABBIT);
  806. ParticleEffect.FLAME.display(1, 1, 1, 0, 100, e.getEntity().getLocation(), 6);
  807. }
  808. if(i.getType().equals(Material.RAW_FISH)){
  809. i.setType(Material.COOKED_FISH);
  810. ParticleEffect.FLAME.display(1, 1, 1, 0, 100, e.getEntity().getLocation(), 6);
  811. }
  812. }
  813. if(e.getEntity() instanceof Squid){
  814. ItemStack fis = new ItemStack(Material.COOKED_FISH, 2);
  815. ItemMeta fiser = fis.getItemMeta();
  816. fiser.setDisplayName("cooked squid");
  817. fis.setItemMeta(fiser);
  818. e.getDrops().add(fis);
  819. }
  820. }
  821. }
  822. @EventHandler
  823. public void AutoSmelt(BlockBreakEvent e){
  824. if(e.getBlock().getWorld().equals(mainw)){
  825. if(e.getBlock().getType().equals(Material.IRON_ORE)){
  826. e.setCancelled(true);
  827. psound(Sound.FIRE, e.getPlayer());
  828. ParticleEffect.FLAME.display(1, 1, 1, 0, 100, e.getBlock().getLocation(), 6);
  829. e.getBlock().setType(Material.AIR);
  830. mainw.dropItem(e.getBlock().getLocation(), new ItemStack(Material.IRON_INGOT, 1));
  831. mainw.spawnEntity(e.getBlock().getLocation(), EntityType.EXPERIENCE_ORB);
  832. }
  833. }
  834. if(e.getBlock().getType().equals(Material.GOLD_ORE)){
  835. e.setCancelled(true);
  836. psound(Sound.FIRE, e.getPlayer());
  837. ParticleEffect.FLAME.display(1, 1, 1, 0, 100, e.getBlock().getLocation(), 6);
  838. e.getBlock().setType(Material.AIR);
  839. mainw.dropItem(e.getBlock().getLocation(), new ItemStack(Material.GOLD_INGOT, 1));
  840. mainw.spawnEntity(e.getBlock().getLocation(), EntityType.EXPERIENCE_ORB);
  841. }
  842. }
  843. @EventHandler
  844. public void entityDamage(EntityDamageEvent e){
  845. if(e.getEntity() instanceof Player ){
  846. if(players.contains(e.getEntity().getName())){
  847. if(e.getCause().equals(DamageCause.FALL)){
  848. if(uhcState.equals(UhcState.GRACE)){
  849. e.setCancelled(true);
  850. }
  851. }
  852. }
  853. }
  854. }
  855. @EventHandler
  856. public void arrowdamage(EntityDamageByEntityEvent e){
  857. if(e.getDamager() instanceof Arrow){
  858. if(uhcState.equals(UhcState.GRACE)){
  859. if(e.getEntity() instanceof Player){
  860. Player p = (Player) e.getEntity();
  861. Arrow a = (Arrow) e.getDamager();
  862. if(a.getShooter() instanceof Player){
  863. Player sho = (Player) a.getShooter();
  864. if(team1.contains(p.getName())){
  865. if(team1.contains(sho)){
  866. e.setCancelled(true);
  867. }
  868. }
  869. if(team2.contains(p.getName())){
  870. if(team2.contains(sho)){
  871. e.setCancelled(true);
  872. }
  873. }
  874. }
  875. }
  876. }
  877. }
  878. if(e.getDamager() instanceof Snowball){
  879. if(uhcState.equals(UhcState.GRACE)){
  880. if(e.getEntity() instanceof Player){
  881. Player p = (Player) e.getEntity();
  882. Arrow a = (Arrow) e.getDamager();
  883. if(a.getShooter() instanceof Player){
  884. Player sho = (Player) a.getShooter();
  885. if(team1.contains(p.getName())){
  886. if(team1.contains(sho)){
  887. e.setCancelled(true);
  888. }
  889. }
  890. if(team2.contains(p.getName())){
  891. if(team2.contains(sho)){
  892. e.setCancelled(true);
  893. }
  894. }
  895. }
  896. }
  897. }
  898. }
  899. }
  900. @EventHandler
  901. public void PowerApple(PlayerItemConsumeEvent e){
  902. Player p = e.getPlayer();
  903. if(e.getItem().getType().equals(Material.GOLDEN_APPLE)){
  904. if(e.getItem().getItemMeta().getDisplayName().contains("Power Apple")){
  905. p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 80, 4));
  906. p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, 80, 4));
  907. }
  908. }
  909. }
  910. @EventHandler
  911. public void PlayerInteract(PlayerInteractEntityEvent e){
  912. if(e.getPlayer().getWorld().getName().equals("world")){
  913. if(e.getRightClicked() instanceof ArmorStand){
  914. e.setCancelled(true);
  915. }
  916. }
  917. }
  918. public void showUHCScoreboard()
  919. {
  920. for(String pla : players){
  921. Player p = Bukkit.getPlayer(pla);
  922. ScoreboardManager manager = Bukkit.getScoreboardManager();
  923. Scoreboard board = manager.getNewScoreboard();
  924. Objective objective = board.registerNewObjective("test", "dummy");
  925. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
  926. objective.setDisplayName(ChatColor.WHITE + "[" + ChatColor.YELLOW + "Ultra Hardcore" + ChatColor.WHITE + "]");
  927. Score score = objective.getScore(ChatColor.YELLOW + "Grace :"); //Get a fake offline player
  928. Score score1 = objective.getScore(ChatColor.YELLOW + "Team 1 :"); //Get a fake offline player
  929. Score score2 = objective.getScore(ChatColor.YELLOW + "Team 2 :"); //Get a fake offline player
  930. score1.setScore(team1.size());
  931. score2.setScore(team2.size());
  932. if(cd2 > 0){
  933. score.setScore(cd2);
  934. } else {
  935. score.setScore(0);
  936. }
  937. p.setScoreboard(board);
  938. }
  939. }
  940. public void uhcsound(Sound s){
  941. for(String pl : players){
  942. Player p = Bukkit.getPlayer(pl);
  943. p.playSound(p.getLocation(), s, 10, 10);
  944. }
  945. for(String pl : spectator){
  946. Player p = Bukkit.getPlayer(pl);
  947. p.playSound(p.getLocation(), s, 10, 10);
  948. }
  949. }
  950. public void psound(Sound s, Player p){
  951. p.playSound(p.getLocation(), s, 10, 10);
  952. }
  953. @EventHandler
  954. public void ItemEnchant(EnchantItemEvent e){
  955. Player p = e.getEnchanter();
  956. if(players.contains(p.getName())){
  957. if(uhcState.equals(UhcState.GRACE)){
  958. psound(Sound.ITEM_BREAK, p);
  959. p.sendMessage(ChatColor.WHITE + "[" + ChatColor.YELLOW + "UHC" + ChatColor.WHITE + "]" + ChatColor.RED + " Enchanting is not allowed in the grace period!");
  960. e.setCancelled(true);
  961. } else {
  962. if(firstenchant == 1){
  963. firstenchant = 0;
  964. uhcbroadcast(p.getName() + " has enchanted the first item!");
  965. }
  966. }
  967. }
  968. }
  969. @EventHandler
  970. public void beaconDestroy(BlockBreakEvent e){
  971. if(players.contains(e.getPlayer().getName())){
  972. if(e.getBlock().getWorld().equals(mainw)){
  973. if(e.getBlock().getType().equals(Material.BEACON)){
  974. e.setCancelled(true);
  975. e.getBlock().setType(Material.AIR);
  976. uhcbroadcast(e.getPlayer().getName() + " has destroyed the beacon! The "+ ChatColor.AQUA + "Beacon Guardians" + ChatColor.GOLD + " have been released!");
  977. mainw.dropItem(e.getBlock().getLocation(), new ItemStack(Material.IRON_INGOT, 32));
  978. IronGolem i1 = (IronGolem) mainw.spawnEntity(e.getBlock().getLocation(), EntityType.IRON_GOLEM);
  979. i1.setCustomName(ChatColor.AQUA + "Beacon Guardian");
  980. i1.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 3));
  981. i1.setTarget(e.getPlayer());
  982. IronGolem i2 = (IronGolem) mainw.spawnEntity(e.getBlock().getLocation(), EntityType.IRON_GOLEM);
  983. i2.setCustomName(ChatColor.AQUA + "Beacon Guardian");
  984. i2.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 3));
  985. i2.setTarget(e.getPlayer());
  986.  
  987. IronGolem i3 = (IronGolem) mainw.spawnEntity(e.getBlock().getLocation(), EntityType.IRON_GOLEM);
  988. i3.setCustomName(ChatColor.AQUA + "Beacon Guardian");
  989. i3.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 3));
  990. i3.setTarget(e.getPlayer());
  991. uhcsound(Sound.IRONGOLEM_DEATH);
  992. uhcsound(Sound.IRONGOLEM_DEATH);
  993. uhcsound(Sound.IRONGOLEM_DEATH);
  994. }
  995. }
  996. }
  997. }
  998. public static Entity[] getNearbyEntities(Location l, int radius) {
  999. int chunkRadius = radius < 16 ? 1 : (radius - (radius % 16)) / 16;
  1000. HashSet <Entity> radiusEntities = new HashSet < Entity > ();
  1001. for (int chX = 0 - chunkRadius; chX <= chunkRadius; chX++) {
  1002. for (int chZ = 0 - chunkRadius; chZ <= chunkRadius; chZ++) {
  1003. int x = (int) l.getX(), y = (int) l.getY(), z = (int) l.getZ();
  1004. for (Entity e: new Location(l.getWorld(), x + (chX * 16), y, z + (chZ * 16)).getChunk().getEntities()) {
  1005. if (e.getLocation().distance(l) <= radius && e.getLocation().getBlock() != l.getBlock())
  1006. radiusEntities.add(e);
  1007. }
  1008. }
  1009. }
  1010. return radiusEntities.toArray(new Entity[radiusEntities.size()]);
  1011. }
  1012.  
  1013. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1014.  
  1015.  
  1016.  
  1017. public void chestTier3(Block b){
  1018. List<Material> materials = Arrays.asList(Material.IRON_INGOT,Material.GOLD_SWORD,Material.SAPLING,Material.LOG,Material.NAME_TAG,Material.WOOD,Material.APPLE,Material.ARROW,Material.BOAT,Material.GLASS_BOTTLE,Material.ROTTEN_FLESH,Material.STRING,Material.BONE,Material.WOOD,Material.APPLE,Material.ARROW,Material.BOAT,Material.GLASS_BOTTLE,Material.ROTTEN_FLESH,Material.STRING,Material.BONE,Material.DEAD_BUSH,Material.DEAD_BUSH,Material.DEAD_BUSH,Material.DEAD_BUSH,Material.DEAD_BUSH);
  1019. Chest c = (Chest) b.getState();
  1020. Inventory chestInventory;
  1021. chestInventory = c.getInventory();
  1022. b.setType(Material.CHEST);
  1023. Random randomvariable = new Random();
  1024.  
  1025.  
  1026. for(int i = 0; i<randomvariable.nextInt(256); i++){
  1027. Random rand = new Random();
  1028. c.getInventory().setItem(rand.nextInt(27), new ItemStack(materials.get(randomvariable.nextInt(materials.size())),
  1029. randomvariable.nextInt(1) + 1));
  1030. }
  1031. }
  1032. public void chestTier2(Block b){
  1033. List<Material> materials = Arrays.asList(Material.BOOK,Material.BOOKSHELF,Material.BAKED_POTATO,Material.COOKED_MUTTON,Material.COOKED_BEEF,Material.GOLD_INGOT,Material.COAL,Material.BOW,Material.BOWL,Material.MUSHROOM_SOUP,Material.SADDLE,Material.BROWN_MUSHROOM,Material.RED_MUSHROOM,Material.EMERALD);
  1034. Chest c = (Chest) b.getState();
  1035. Inventory chestInventory;
  1036. chestInventory = c.getInventory();
  1037. b.setType(Material.CHEST);
  1038. Random randomvariable = new Random();
  1039.  
  1040.  
  1041. for(int i = 0; i<randomvariable.nextInt(128); i++){
  1042. Random rand = new Random();
  1043. c.getInventory().setItem(rand.nextInt(27), new ItemStack(materials.get(randomvariable.nextInt(materials.size())),
  1044. randomvariable.nextInt(1) + 1));
  1045. }
  1046. }
  1047. public void chestTier1(Block b){
  1048. List<Material> materials = Arrays.asList(Material.IRON_HELMET,Material.DIAMOND,Material.DIAMOND_HELMET,Material.IRON_CHESTPLATE,Material.IRON_LEGGINGS,Material.GOLD_BOOTS,Material.ENCHANTMENT_TABLE,Material.BREWING_STAND,Material.GLOWSTONE_DUST);
  1049. Chest c = (Chest) b.getState();
  1050. Inventory chestInventory;
  1051. chestInventory = c.getInventory();
  1052. b.setType(Material.CHEST);
  1053. Random randomvariable = new Random();
  1054.  
  1055.  
  1056. for(int i = 0; i<randomvariable.nextInt(64); i++){
  1057. Random rand = new Random();
  1058. c.getInventory().setItem(rand.nextInt(27), new ItemStack(materials.get(randomvariable.nextInt(materials.size())),
  1059. randomvariable.nextInt(1) + 1));
  1060. }
  1061. }
  1062. public void Trap1(Block b, Player p){
  1063. Random rand = new Random();
  1064. int trapnumb = rand.nextInt(8)+1;
  1065. World w = b.getWorld();
  1066. Location loc = b.getLocation();
  1067. b.setType(Material.AIR);
  1068. if(trapnumb == 1){
  1069. w.spawn(loc, Silverfish.class);
  1070. w.spawn(loc, Silverfish.class);
  1071. w.spawn(loc, Silverfish.class);
  1072. w.spawn(loc, Silverfish.class);
  1073. } else if(trapnumb == 2){
  1074. p.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 100));
  1075. } else if(trapnumb == 3){
  1076. p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 500, 100));
  1077. } else if(trapnumb == 4){
  1078. b.setType(Material.BEDROCK);
  1079. } else if(trapnumb == 5){
  1080. b.setType(Material.LAVA);
  1081. } else if(trapnumb == 6){
  1082. p.setFoodLevel(2);
  1083. } else if(trapnumb == 7){
  1084. Slime e = p.getWorld().spawn(p.getLocation(), Slime.class);
  1085. e.setCustomName(ChatColor.GREEN + "The Blob");
  1086. e.setSize(2);
  1087. e.setHealth(40);
  1088. e.setCustomNameVisible(true);
  1089. p.setPassenger(e);
  1090. } else if(trapnumb == 8){
  1091. b.setType(Material.TNT);
  1092. TNTPrimed tn = b.getWorld().spawn(b.getLocation(), TNTPrimed.class);
  1093. tn.setFuseTicks(40);
  1094. }
  1095. }
  1096. @EventHandler
  1097. public void SpawnChest(BlockBreakEvent e){
  1098. if(chestmode == 1){
  1099. Block b = e.getBlock();
  1100. Player p = e.getPlayer();
  1101. if(p.getWorld().equals(mainw)){
  1102. Random rand = new Random();
  1103. int numb = rand.nextInt(200)+1;
  1104. if(numb == 1){
  1105. e.setCancelled(true);
  1106. b.setType(Material.TRAPPED_CHEST);
  1107. psound(Sound.ZOMBIE_WOODBREAK, p);
  1108. placed.put(b.getLocation(), Material.AIR);
  1109. }
  1110. }
  1111. }
  1112. }
  1113. @EventHandler
  1114. public void chestopen(PlayerInteractEvent e){
  1115. if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)){
  1116. Block b = e.getClickedBlock();
  1117. if(b.getType().equals(Material.TRAPPED_CHEST)){
  1118. if(e.getPlayer().getWorld().equals(mainw)){
  1119. Random rand2 = new Random();
  1120. int numb2 = rand2.nextInt(10)+1;
  1121. e.setCancelled(true);
  1122. if(numb2 < 3){
  1123. Trap1(e.getClickedBlock(), e.getPlayer());
  1124. uhcbroadcast(e.getPlayer().getName() + " Found a Trapped chest!");
  1125. } else if(numb2 < 7){
  1126. b.setType(Material.CHEST);
  1127. chestTier3(e.getClickedBlock());
  1128. uhcbroadcast(e.getPlayer().getName() + " Found a Tier 3 chest!");
  1129. } else if(numb2 < 9){
  1130. b.setType(Material.CHEST);
  1131. chestTier2(e.getClickedBlock());
  1132. uhcbroadcast(e.getPlayer().getName() + " Found a Tier 2 chest!");
  1133. } else if(numb2 < 11){
  1134. b.setType(Material.CHEST);
  1135. chestTier1(e.getClickedBlock());
  1136. uhcbroadcast(e.getPlayer().getName() + " Found a Tier 1 chest!");
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. public void DeathPath(Player p){
  1143. if(players.contains(p.getName())){
  1144. players.remove(p.getName());
  1145. uhcbroadcast(p.getName() + " died! "+players.size()+" players left!");
  1146. uhcsound(Sound.ENDERDRAGON_HIT);
  1147. FileConfiguration con = getConfig();
  1148. con.get("lobby.x");
  1149. con.get("lobby.y");
  1150. con.get("lobby.z");
  1151. con.get("lobby.yaw");
  1152. con.get("lobby.pitch");
  1153. con.get("lobby.world");
  1154. Location uhcspawn = new Location((World) Bukkit.getWorld((String) con.get("spawn.world")),(double) con.get("spawn.x"),(double) con.get("spawn.y"),(double) con.get("spawn.z"));
  1155. uhcspawn.setPitch((float) con.getDouble("spawn.pitch"));
  1156. uhcspawn.setPitch((float) con.getDouble("spawn.yaw"));
  1157. if(team1.contains(p.getName())){
  1158. team1.remove(p.getName());
  1159. }
  1160. if(team2.contains(p.getName())){
  1161. team2.remove(p.getName());
  1162. }
  1163. spectator.add(p.getName());
  1164. p.setGameMode(GameMode.SPECTATOR);
  1165. p.teleport(midloc);
  1166. if(team1.size() == 0){
  1167. uhcbroadcast("team 2 has won the game!");
  1168. uhcsound(Sound.ENDERDRAGON_GROWL);
  1169. ScoreboardManager manager = Bukkit.getScoreboardManager();
  1170. p.setScoreboard(manager.getNewScoreboard());
  1171. restoreBlocks();
  1172. setState(GameState.WAITING);
  1173. for (String pl : players){
  1174. Player pla = Bukkit.getPlayer(pl);
  1175. pla.teleport(uhcspawn);
  1176. pla.setGameMode(GameMode.ADVENTURE);
  1177. pla.getInventory().clear();
  1178. pla.getEquipment().clear();
  1179. pla.getInventory().setHelmet(null);
  1180. pla.getInventory().setChestplate(null);
  1181. pla.getInventory().setLeggings(null);
  1182. pla.getInventory().setBoots(null);
  1183. pla.setHealth(20);
  1184. pla.setFoodLevel(20);
  1185. }
  1186. for (String pl : spectator){
  1187. Player pla = Bukkit.getPlayer(pl);
  1188. pla.teleport(uhcspawn);
  1189. pla.setGameMode(GameMode.ADVENTURE);
  1190. }
  1191. players.clear();
  1192. team1.clear();
  1193. team2.clear();
  1194. spectator.clear();
  1195. canstart = 1;
  1196. cd = -15;
  1197. cd2 = -15;
  1198. } else if(team2.size() == 0){
  1199. uhcbroadcast("team 1 has won the game!");
  1200. uhcsound(Sound.ENDERDRAGON_GROWL);
  1201. ScoreboardManager manager = Bukkit.getScoreboardManager();
  1202. p.setScoreboard(manager.getNewScoreboard());
  1203. restoreBlocks();
  1204. setState(GameState.WAITING);
  1205. for (String pl : players){
  1206. Player pla = Bukkit.getPlayer(pl);
  1207. pla.teleport(uhcspawn);
  1208. pla.setGameMode(GameMode.ADVENTURE);
  1209. pla.getInventory().clear();
  1210. pla.getEquipment().clear();
  1211. pla.getInventory().setHelmet(null);
  1212. pla.getInventory().setChestplate(null);
  1213. pla.getInventory().setLeggings(null);
  1214. pla.getInventory().setBoots(null);
  1215. pla.setHealth(20);
  1216. pla.setFoodLevel(20);
  1217. }
  1218. for (String pl : spectator){
  1219. Player pla = Bukkit.getPlayer(pl);
  1220. pla.teleport(uhcspawn);
  1221. pla.setGameMode(GameMode.ADVENTURE);
  1222. }
  1223. players.clear();
  1224. team1.clear();
  1225. team2.clear();
  1226. spectator.clear();
  1227. canstart = 1;
  1228. cd = -15;
  1229. cd2 = -15;
  1230. }
  1231. }
  1232. }
  1233. @EventHandler
  1234. public void firstblock(BlockBreakEvent e){
  1235. if(e.getPlayer().getWorld().equals(mainw)){
  1236. if(players.contains(e.getPlayer().getName())){
  1237. if(e.getBlock().getType().equals(Material.COAL_ORE)){
  1238. if(firstcoal == 1){
  1239. firstcoal = 0;
  1240. uhcbroadcast(e.getPlayer().getName() + " has found the first coal!");
  1241. }
  1242. }
  1243. if(e.getBlock().getType().equals(Material.IRON_ORE)){
  1244. if(firstiron == 1){
  1245. firstiron = 0;
  1246. uhcbroadcast(e.getPlayer().getName() + " has found the first iron!");
  1247. }
  1248. }
  1249. if(e.getBlock().getType().equals(Material.GOLD_ORE)){
  1250. if(firstgold == 1){
  1251. firstgold = 0;
  1252. uhcbroadcast(e.getPlayer().getName() + " has found the first gold!");
  1253. }
  1254. }
  1255. if(e.getBlock().getType().equals(Material.DIAMOND_ORE)){
  1256. if(firstdiamond == 1){
  1257. firstdiamond = 0;
  1258. uhcbroadcast(e.getPlayer().getName() + " has found the first diamonds! Ooh... Shiny!");
  1259. }
  1260. }
  1261. if(e.getBlock().getType().equals(Material.REDSTONE_ORE)){
  1262. if(firstredstone == 1){
  1263. firstredstone = 0;
  1264. uhcbroadcast(e.getPlayer().getName() + " has found the first redstone!");
  1265. }
  1266. }
  1267. if(e.getBlock().getType().equals(Material.EMERALD_ORE)){
  1268. if(firstemerald == 1){
  1269. firstemerald = 0;
  1270. uhcbroadcast(e.getPlayer().getName() + " has found the first emerald!");
  1271. }
  1272. }
  1273. if(e.getBlock().getType().equals(Material.LAPIS_ORE)){
  1274. if(firstlapis == 1){
  1275. firstlapis = 0;
  1276. uhcbroadcast(e.getPlayer().getName() + " has found the first lapis lazuli!");
  1277. }
  1278. }
  1279. }
  1280. }
  1281. }
  1282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement