Advertisement
Whoneedspacee

Untitled

Feb 7th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.71 KB | None | 0 0
  1. package me.firstflames;
  2.  
  3. import java.util.HashMap;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.Sound;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.EventHandler;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.event.block.*;
  13. import org.bukkit.event.player.PlayerInteractEvent;
  14. import org.bukkit.event.player.PlayerJoinEvent;
  15. import org.bukkit.plugin.java.JavaPlugin;
  16. import org.bukkit.util.Vector;
  17.  
  18. import net.minecraft.server.v1_8_R3.Block;
  19.  
  20. public class FlashListener extends JavaPlugin implements Listener {
  21.  
  22. Integer timer;
  23. Integer charges;
  24. Player p;
  25. Block pBlockLooking;
  26. Location pBlockLocation;
  27. double pBlockX;
  28. double pBlockY;
  29. double pBlockZ;
  30. double pBlockLookX;
  31. double pBlockLookY;
  32. double pBlockLookZ;
  33. Location pLocation;
  34. Location pLocationCheck;
  35. float pPitch;
  36. float pYaw;
  37. Vector pDir;
  38. int done;
  39. public Vector stopVelocity = new Vector(0, 0, 0);
  40. int first;
  41. Material blockFound;
  42. Location doLocation;
  43. HashMap<Player, Integer> map = new HashMap<Player, Integer>();
  44. HashMap<Player, Integer> map2 = new HashMap<Player, Integer>();
  45.  
  46. @Override
  47. public void onEnable() {
  48. getServer().getPluginManager().registerEvents(this, this);
  49.  
  50. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  51. @Override
  52. public void run() {
  53. for (Player p : map.keySet()) {
  54. charges = map.get(p);
  55. timer = map2.get(p);
  56. if (charges < 6 && p.getItemInHand().getType() == Material.GOLD_AXE) {
  57. if (timer >= 3) {
  58. map2.put(p, timer = 0);
  59. map.put(p, ++charges);
  60. p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
  61. } else {
  62. map2.put(p, ++timer);
  63. }
  64. } else if (charges < 5 && p.getItemInHand().getType() == Material.DIAMOND_AXE) {
  65. if (timer >= 4) {
  66. map2.put(p, timer = 0);
  67. map.put(p, ++charges);
  68. p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
  69. } else {
  70. map2.put(p, ++timer);
  71. }
  72. } else if (charges < 5 && p.getItemInHand().getType() == Material.IRON_AXE) {
  73. if (timer >= 4) {
  74. map2.put(p, timer = 0);
  75. map.put(p, ++charges);
  76. p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
  77. } else {
  78. map2.put(p, ++timer);
  79. }
  80. }
  81. }
  82. }
  83. }, 20, 20);
  84.  
  85. }
  86.  
  87. @EventHandler
  88. public void PlayerInteract(PlayerInteractEvent event) {
  89. p = event.getPlayer();
  90. charges = map.get(p);
  91. if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.IRON_AXE
  92. && charges > 0) {
  93. // Run code here
  94. first = 1;
  95. pYaw = p.getLocation().getYaw();
  96. pPitch = p.getLocation().getPitch();
  97. for (int distTele = 1; distTele < 11; distTele++) {
  98. pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  99. .toLocation(p.getWorld());
  100. pLocationCheck = pLocation;
  101. pLocationCheck.setY(pLocation.getY() + 2);
  102. blockFound = pLocationCheck.getBlock().getType();
  103. if (blockFound == Material.AIR && done == 0) {
  104. doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  105. .toLocation(p.getWorld());
  106. first = 0;
  107. } else if (blockFound != Material.AIR && first == 1) {
  108. done = 1;
  109. doLocation = p.getLocation();
  110. } else {
  111. done = 1;
  112. first = 0;
  113. }
  114. }
  115. doLocation.setYaw(pYaw);
  116. doLocation.setPitch(pPitch);
  117. p.teleport(doLocation);
  118. done = 0;
  119. p.setVelocity(stopVelocity);
  120. p.setFallDistance(0);
  121. //p.playSound(p.getLocation(), Sound.BLOCK_ANVIL_BREAK, 1, 1);
  122. map.put(p, --charges);
  123. p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
  124. } else if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.DIAMOND_AXE
  125. && charges > 0) {
  126. // Run code here
  127. first = 1;
  128. pYaw = p.getLocation().getYaw();
  129. pPitch = p.getLocation().getPitch();
  130. for (int distTele = 1; distTele < 11; distTele++) {
  131. pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  132. .toLocation(p.getWorld());
  133. pLocationCheck = pLocation;
  134. pLocationCheck.setY(pLocation.getY() + 2);
  135. blockFound = pLocationCheck.getBlock().getType();
  136. if (blockFound == Material.AIR && done == 0) {
  137. doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  138. .toLocation(p.getWorld());
  139. first = 0;
  140. } else if (blockFound != Material.AIR && first == 1) {
  141. done = 1;
  142. doLocation = p.getLocation();
  143. } else {
  144. done = 1;
  145. first = 0;
  146. }
  147. }
  148. doLocation.setYaw(pYaw);
  149. doLocation.setPitch(pPitch);
  150. p.teleport(doLocation);
  151. done = 0;
  152. p.setVelocity(stopVelocity);
  153. p.setFallDistance(0);
  154. p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1, 1);
  155. map.put(p, --charges);
  156. p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
  157. } else if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.GOLD_AXE
  158. && charges > 0) {
  159. // Run code here
  160. first = 1;
  161. pYaw = p.getLocation().getYaw();
  162. pPitch = p.getLocation().getPitch();
  163. for (int distTele = 1; distTele < 11; distTele++) {
  164. pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  165. .toLocation(p.getWorld());
  166. pLocationCheck = pLocation;
  167. pLocationCheck.setY(pLocation.getY() + 2);
  168. blockFound = pLocationCheck.getBlock().getType();
  169. if (blockFound == Material.AIR && done == 0) {
  170. doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  171. .toLocation(p.getWorld());
  172. first = 0;
  173. } else if (blockFound != Material.AIR && first == 1) {
  174. done = 1;
  175. doLocation = p.getLocation();
  176. } else {
  177. done = 1;
  178. first = 0;
  179. }
  180. }
  181. doLocation.setYaw(pYaw);
  182. doLocation.setPitch(pPitch);
  183. p.teleport(doLocation);
  184. done = 0;
  185. p.setVelocity(stopVelocity);
  186. p.setFallDistance(0);
  187. p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1, 1);
  188. map.put(p, --charges);
  189. p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
  190. }
  191. if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.IRON_AXE
  192. && charges > 0) {
  193. // Run code here
  194. first = 1;
  195. pYaw = p.getLocation().getYaw();
  196. pPitch = p.getLocation().getPitch();
  197. for (int distTele = 1; distTele < 11; distTele++) {
  198. pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  199. .toLocation(p.getWorld());
  200. pLocationCheck = pLocation;
  201. pLocationCheck.setY(pLocation.getY() + 2);
  202. blockFound = pLocationCheck.getBlock().getType();
  203. if (blockFound == Material.AIR && done == 0) {
  204. doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  205. .toLocation(p.getWorld());
  206. first = 0;
  207. } else if (blockFound != Material.AIR && first == 1) {
  208. done = 1;
  209. doLocation = p.getLocation();
  210. } else {
  211. done = 1;
  212. first = 0;
  213. }
  214. }
  215. doLocation.setYaw(pYaw);
  216. doLocation.setPitch(pPitch);
  217. p.teleport(doLocation);
  218. done = 0;
  219. p.setVelocity(stopVelocity);
  220. p.setFallDistance(0);
  221. p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1, 1);
  222. map.put(p, --charges);
  223. p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
  224. } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.DIAMOND_AXE
  225. && charges > 0) {
  226. // Run code here
  227. first = 1;
  228. pYaw = p.getLocation().getYaw();
  229. pPitch = p.getLocation().getPitch();
  230. for (int distTele = 1; distTele < 11; distTele++) {
  231. pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  232. .toLocation(p.getWorld());
  233. pLocationCheck = pLocation;
  234. pLocationCheck.setY(pLocation.getY() + 2);
  235. blockFound = pLocationCheck.getBlock().getType();
  236. if (blockFound == Material.AIR && done == 0) {
  237. doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  238. .toLocation(p.getWorld());
  239. first = 0;
  240. } else if (blockFound != Material.AIR && first == 1) {
  241. done = 1;
  242. doLocation = p.getLocation();
  243. } else {
  244. done = 1;
  245. first = 0;
  246. }
  247. }
  248. doLocation.setYaw(pYaw);
  249. doLocation.setPitch(pPitch);
  250. p.teleport(doLocation);
  251. done = 0;
  252. p.setVelocity(stopVelocity);
  253. p.setFallDistance(0);
  254. p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1, 1);
  255. map.put(p, --charges);
  256. p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
  257. } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.GOLD_AXE
  258. && charges > 0) {
  259. // Run code here
  260. first = 1;
  261. pYaw = p.getLocation().getYaw();
  262. pPitch = p.getLocation().getPitch();
  263. for (int distTele = 1; distTele < 11; distTele++) {
  264. pLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  265. .toLocation(p.getWorld());
  266. pLocationCheck = pLocation;
  267. pLocationCheck.setY(pLocation.getY() + 2);
  268. blockFound = pLocationCheck.getBlock().getType();
  269. if (blockFound == Material.AIR && done == 0) {
  270. doLocation = p.getLocation().toVector().add(p.getLocation().getDirection().multiply(distTele))
  271. .toLocation(p.getWorld());
  272. first = 0;
  273. } else if (blockFound != Material.AIR && first == 1) {
  274. done = 1;
  275. doLocation = p.getLocation();
  276. } else {
  277. done = 1;
  278. first = 0;
  279. }
  280. }
  281. doLocation.setYaw(pYaw);
  282. doLocation.setPitch(pPitch);
  283. p.teleport(doLocation);
  284. done = 0;
  285. p.setVelocity(stopVelocity);
  286. p.setFallDistance(0);
  287. p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 1, 1);
  288. map.put(p, --charges);
  289. p.sendMessage(ChatColor.GRAY + "Flash Charges: " + ChatColor.YELLOW + charges);
  290. } else if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.GOLD_AXE
  291. && charges == 0) {
  292. p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
  293. } else if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.IRON_AXE
  294. && charges == 0) {
  295. p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
  296. } else if (event.getAction() == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.DIAMOND_AXE
  297. && charges == 0) {
  298. p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
  299. } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.GOLD_AXE
  300. && charges == 0) {
  301. p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
  302. } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.IRON_AXE
  303. && charges == 0) {
  304. p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
  305. } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && p.getItemInHand().getType() == Material.DIAMOND_AXE
  306. && charges == 0) {
  307. p.sendMessage(ChatColor.GRAY + "You have no " + ChatColor.GREEN + "Flash Charges" + ChatColor.GRAY + ".");
  308. }
  309. }
  310.  
  311. @EventHandler
  312. public void PlayerJoin(PlayerJoinEvent event) {
  313. p = event.getPlayer();
  314. charges = 0;
  315. timer = 0;
  316. map.put(p, charges);
  317. map2.put(p, timer);
  318. }
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement