CubyGC

Untitled

Jun 2nd, 2020
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. package cy.uhc.scenarios.threads;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.GameMode;
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.block.Block;
  8. import org.bukkit.block.Chest;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.inventory.Inventory;
  11. import org.bukkit.inventory.ItemStack;
  12. import org.bukkit.metadata.FixedMetadataValue;
  13.  
  14. import cy.uhc.game.GameManager;
  15. import cy.uhc.game.UhcItems;
  16. import cy.uhc.main.UhcCore;
  17. import cy.uhc.scenarios.Scenario;
  18. import de.inventivegames.hologram.Hologram;
  19. import de.inventivegames.hologram.HologramAPI;
  20.  
  21. import java.util.List;
  22. import java.util.UUID;
  23.  
  24. public class TimebombThread implements Runnable{
  25.  
  26. private Block chest1;
  27. private Block chest2;
  28. private TimebombThread thread;
  29. private long timeLeft;
  30. private Location loc;
  31. private List<ItemStack> drops;
  32. private boolean spawned;
  33. private UUID killer;
  34. private String deadname;
  35. private Hologram holo;
  36.  
  37. public TimebombThread(List<ItemStack> drops, Location loc, UUID kl, UUID d){
  38. this.drops = drops;
  39. this.loc = loc;
  40. thread = this;
  41. timeLeft = 30;
  42. spawned = false;
  43. killer = kl;
  44. deadname = Bukkit.getOfflinePlayer(d).getName();
  45. }
  46.  
  47. @Override
  48. public void run() {
  49.  
  50. if (!spawned){
  51. spawnChest();
  52. }
  53.  
  54. if (timeLeft > 0){
  55. timeLeft--;
  56. Bukkit.getScheduler().runTaskLater(UhcCore.getPlugin(),thread,20L);
  57. if (holo.isSpawned()) {
  58. holo.setText("§e"+timeLeft);
  59. }
  60. if (timeLeft <= 10) {
  61. for(Player nearp : chest1.getLocation().getWorld().getPlayers()) {
  62. if (nearp != null) {
  63. if (nearp.getGameMode() == GameMode.SURVIVAL) {
  64. if (chest1.getLocation().distance(nearp.getLocation()) <= 16) {
  65. String lines = "§c§m-----------------------------------------------";
  66. GameManager.getGameManager().getPlayersManager().sendLanguageMSG(nearp, lines, lines);
  67. GameManager.getGameManager().getPlayersManager().sendLanguageMSG(nearp,
  68. "§7[§dTimeBomb§7] §cYou are near the chest from §f"+deadname+" §cis gonna explote in §c§l"+timeLeft+"s",
  69. "§7[§dTimeBomb§7] §cEsta cerca del cofre de §f"+deadname+" §cy va a explotar en §c§l"+timeLeft+"s");
  70. GameManager.getGameManager().getPlayersManager().sendLanguageMSG(nearp, lines, lines);
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }else {
  77. if (holo.isSpawned()) {
  78. holo.despawn();
  79. }
  80. GameManager.getGameManager().getPlayersManager().sendLanguageBC("§7[§dTimeBomb§7] §f"+deadname+"'s corpse has exploded!",
  81. "§7[§dTimeBomb§7] §fCadaver de "+deadname+" ah explotado!");
  82. chest1.setType(Material.AIR);
  83. chest2.setType(Material.AIR);
  84. chest1.getWorld().createExplosion(chest1.getLocation(), 5.0F);
  85. }
  86. }
  87.  
  88. private void spawnChest(){
  89.  
  90. spawned = true;
  91.  
  92. chest1 = loc.getBlock();
  93. loc.add(1, 0, 0);
  94. chest2 = loc.getBlock();
  95.  
  96. chest1.setType(Material.CHEST);
  97. chest2.setType(Material.CHEST);
  98. if (killer != null) {
  99. if (GameManager.getGameManager().getScenarioManager().isActivated(Scenario.SAFELOOT)) {
  100. chest1.setMetadata("SafeLoot", new FixedMetadataValue(UhcCore.getPlugin(), killer));
  101. chest2.setMetadata("SafeLoot", new FixedMetadataValue(UhcCore.getPlugin(), killer));
  102. }
  103. }
  104.  
  105. Chest chest = (Chest) chest1.getState();
  106. Inventory inv = chest.getInventory();
  107.  
  108. inv.addItem(UhcItems.createGoldenHeadg(1));
  109. Location hololoc = new Location(chest.getWorld(),chest.getLocation().getBlockX()+1, chest.getLocation().getBlockY()+1, chest.getLocation().getBlockZ()+1);
  110. holo = HologramAPI.createHologram(hololoc, "§e"+timeLeft);
  111. holo.spawn();
  112.  
  113. if (drops != null) {
  114. for (ItemStack drop : drops){
  115. if (drop != null) {
  116. if (drop.getType() != Material.AIR) {
  117. inv.addItem(drop);
  118. }
  119. }
  120. }
  121. }
  122.  
  123. Chest chest1B = (Chest) chest1.getState();
  124. Chest chest2B = (Chest) chest2.getState();
  125. Location removeblock1 = new Location(chest1B.getWorld(),chest1B.getLocation().getBlockX(), chest1B.getLocation().getBlockY()+1.3, chest1B.getLocation().getBlockZ());
  126. Location removeblock2 = new Location(chest2B.getWorld(),chest2B.getLocation().getBlockX(), chest2B.getLocation().getBlockY()+1.3, chest2B.getLocation().getBlockZ());
  127. removeblock1.getBlock().setType(Material.AIR);
  128. removeblock2.getBlock().setType(Material.AIR);
  129.  
  130. loc.add(1.0,1.3,.5);
  131. }
  132.  
  133. }
Add Comment
Please, Sign In to add comment