Advertisement
Guest User

Untitled

a guest
Jan 25th, 2021
165
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //MAIN
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.plugin.PluginManager;
  5. import org.bukkit.plugin.java.JavaPlugin;
  6.  
  7.  
  8. public class Main extends JavaPlugin{
  9.  
  10. private static Main instance;
  11.  
  12. @Override
  13. public void onEnable() {
  14. PluginManager pm = Bukkit.getPluginManager();
  15.  
  16. pm.registerEvents(new ManeuvergearListener(), this);
  17.  
  18. super.onEnable();
  19. }
  20.  
  21. public static Main getInstance() {
  22. return instance;
  23. }
  24.  
  25. }
  26.  
  27.  
  28. //LISTENER
  29. import org.bukkit.Bukkit;
  30. import org.bukkit.GameMode;
  31. import org.bukkit.Location;
  32. import org.bukkit.Material;
  33. import org.bukkit.craftbukkit.v1_16_R3.entity.CraftBat;
  34. import org.bukkit.entity.*;
  35. import org.bukkit.event.EventHandler;
  36. import org.bukkit.event.Listener;
  37. import org.bukkit.event.block.Action;
  38. import org.bukkit.event.entity.EntityUnleashEvent;
  39. import org.bukkit.event.entity.PlayerDeathEvent;
  40. import org.bukkit.event.entity.ProjectileHitEvent;
  41. import org.bukkit.event.player.PlayerChangedWorldEvent;
  42. import org.bukkit.event.player.PlayerGameModeChangeEvent;
  43. import org.bukkit.event.player.PlayerInteractEntityEvent;
  44. import org.bukkit.event.player.PlayerInteractEvent;
  45. import org.bukkit.event.player.PlayerToggleFlightEvent;
  46. import org.bukkit.inventory.EquipmentSlot;
  47. import org.bukkit.inventory.ItemStack;
  48. import org.bukkit.inventory.meta.ItemMeta;
  49. import org.bukkit.util.Vector;
  50.  
  51. import java.util.*;
  52.  
  53.  
  54. public class ManeuvergearListener implements Listener {
  55.  
  56. private static ArrayList<Player> throwed = new ArrayList<>();
  57. private static HashMap<Player, Location> thrownOnBlock = new HashMap<>();
  58. private static HashMap<Player, LivingEntity> thrownOnEntity = new HashMap<>();
  59.  
  60. private static int boost = 2;
  61. private static int distance = 60;
  62.  
  63. @EventHandler
  64. private void onThrow(PlayerInteractEvent e) {
  65. if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
  66. if (e.getHand().equals(EquipmentSlot.HAND)) {
  67. if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().equalsIgnoreCase("§l3D MANEUVER GEAR")) {
  68. Player p = e.getPlayer();
  69. if (p.getGameMode() != GameMode.CREATIVE) {
  70. if (!throwed.contains(p)) {
  71. throwed.add(p);
  72. p.launchProjectile(Arrow.class);
  73.  
  74. Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
  75. @Override
  76. public void run() {
  77. if (!thrownOnBlock.containsKey(p) && !thrownOnEntity.containsKey(p)) {
  78. throwed.remove(p);
  79. }
  80. }
  81. }, 20 * 10);
  82. } else {
  83. if (thrownOnBlock.containsKey(p)) {
  84. boostPlayer(p, thrownOnBlock.get(p));
  85. } else if (thrownOnEntity.containsKey(p)) {
  86. boostPlayer(p, thrownOnEntity.get(p).getLocation());
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94.  
  95. @EventHandler
  96. public void onDeath(PlayerDeathEvent e) {
  97. Player p = e.getEntity().getPlayer();
  98. if(throwed.contains(p)) {
  99. throwed.remove(p);
  100. }
  101. if(thrownOnEntity.containsKey(p)) {
  102. Location loc = thrownOnEntity.get(p).getLocation();
  103.  
  104. for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
  105. LivingEntity livingEntity = (LivingEntity) ent;
  106. livingEntity.setLeashHolder(null);
  107. destroyCable(p, loc);
  108. thrownOnEntity.remove(p);
  109. }
  110. }
  111. if(thrownOnBlock.containsKey(p)) {
  112. Location loc = thrownOnBlock.get(p);
  113. for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
  114. LivingEntity livingEntity = (LivingEntity) ent;
  115. livingEntity.setLeashHolder(null);
  116. destroyCable(p, loc);
  117. thrownOnBlock.remove(p);
  118. }
  119. }
  120.  
  121.  
  122. }
  123.  
  124. @EventHandler
  125. public void onGameModeChange(PlayerGameModeChangeEvent e) {
  126. Player p = e.getPlayer();
  127. if(throwed.contains(p)) {
  128. throwed.remove(p);
  129. }
  130. if(thrownOnEntity.containsKey(p)) {
  131. Location loc = thrownOnEntity.get(p).getLocation();
  132.  
  133. for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
  134. LivingEntity livingEntity = (LivingEntity) ent;
  135. livingEntity.setLeashHolder(null);
  136. destroyCable(p, loc);
  137. thrownOnEntity.remove(p);
  138. }
  139. }
  140. if(thrownOnBlock.containsKey(p)) {
  141. Location loc = thrownOnBlock.get(p);
  142. for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
  143. LivingEntity livingEntity = (LivingEntity) ent;
  144. livingEntity.setLeashHolder(null);
  145. destroyCable(p, loc);
  146. thrownOnBlock.remove(p);
  147. }
  148. }
  149. }
  150.  
  151. @EventHandler
  152. private void onHit(ProjectileHitEvent e) {
  153. if (e.getEntity().getShooter() instanceof Player) {
  154. Player p = (Player) e.getEntity().getShooter();
  155.  
  156. if (!thrownOnBlock.containsKey(p) && !thrownOnEntity.containsKey(p)) {
  157. Arrow arrow = (Arrow) e.getEntity();
  158.  
  159. if (e.getHitBlock() != null && e.getHitEntity() == null) {
  160. if (!(p.getLocation().distance(e.getHitBlock().getLocation()) >= distance)) {
  161. thrownOnBlock.put(p, e.getHitBlock().getLocation());
  162.  
  163. Bat bat = p.getWorld().spawn(e.getHitBlock().getLocation(), Bat.class);
  164. bat.setAI(false);
  165. bat.setSilent(true);
  166. bat.setInvisible(true);
  167. bat.setInvulnerable(true);
  168.  
  169. bat.setLeashHolder(p);
  170.  
  171. p.setAllowFlight(true);
  172. } else {
  173. throwed.remove(p);
  174. }
  175. } else if (e.getHitEntity() != null && e.getHitBlock() == null) {
  176. if (!(p.getLocation().distance(e.getHitEntity().getLocation()) >= distance)) {
  177. LivingEntity entity = (LivingEntity) e.getHitEntity();
  178. entity.setLeashHolder(p);
  179.  
  180. thrownOnEntity.put(p, entity);
  181. p.setAllowFlight(true);
  182. } else {
  183. throwed.remove(p);
  184. }
  185. }
  186.  
  187. arrow.remove();
  188. }
  189. }
  190. }
  191.  
  192. @EventHandler
  193. private void onUnleash(EntityUnleashEvent e) {
  194. LivingEntity livingEntity = (LivingEntity) e.getEntity();
  195.  
  196. if (livingEntity.getLeashHolder() instanceof Player) {
  197. Player p = (Player) livingEntity.getLeashHolder();
  198.  
  199. if (thrownOnBlock.containsKey(p) || thrownOnEntity.containsKey(p)) {
  200. destroyCable(p, livingEntity.getLocation());
  201. }
  202. }
  203. }
  204.  
  205. @EventHandler
  206. public void onFlightAttempt(PlayerToggleFlightEvent e) {
  207. Player p = e.getPlayer();
  208.  
  209. if ((p.getGameMode() != GameMode.CREATIVE) && (p.getAllowFlight())) {
  210. e.setCancelled(true);
  211.  
  212. p.setAllowFlight(false);
  213. p.setFlying(false);
  214.  
  215. if (thrownOnBlock.containsKey(p)) {
  216. Location loc = thrownOnBlock.get(p);
  217.  
  218. for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
  219. LivingEntity livingEntity = (LivingEntity) ent;
  220. if (ent instanceof CraftBat) {
  221. livingEntity.setHealth(0);
  222. }
  223. }
  224.  
  225. destroyCable(p, loc);
  226. } else if (thrownOnEntity.containsKey(p)) {
  227. Location loc = thrownOnEntity.get(p).getLocation();
  228.  
  229. for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
  230. LivingEntity livingEntity = (LivingEntity) ent;
  231. livingEntity.setLeashHolder(null);
  232.  
  233. throwed.remove(p);
  234. thrownOnBlock.remove(p);
  235. thrownOnEntity.remove(p);
  236. }
  237. }
  238. }
  239. }
  240.  
  241. @EventHandler
  242. private void onInteract(PlayerInteractEntityEvent e) {
  243. Player p = e.getPlayer();
  244.  
  245. if (thrownOnEntity.containsKey(p)) {
  246. LivingEntity rightclicked = (LivingEntity) e.getRightClicked();
  247. LivingEntity entity = thrownOnEntity.get(e.getPlayer());
  248.  
  249. if (rightclicked.equals(entity)) {
  250. e.setCancelled(true);
  251. boostPlayer(p, thrownOnEntity.get(p).getLocation());
  252. }
  253. } else {
  254. if (e.getRightClicked() instanceof CraftBat) {
  255. e.setCancelled(true);
  256. boostPlayer(p, thrownOnBlock.get(p));
  257. }
  258. }
  259. }
  260.  
  261. private static void boostPlayer(Player p, Location to) {
  262. Vector v = to.toVector().subtract(p.getLocation().toVector());
  263.  
  264. long distance = Math.round(p.getLocation().distance(to) * 100) / 100;
  265.  
  266. List<Integer> gas = new ArrayList<>();
  267.  
  268. if (p.getInventory().contains(Material.POTION)) {
  269. for (ItemStack items : p.getInventory().getContents()) {
  270. if (items != null) {
  271. if (items.getItemMeta().getDisplayName().equalsIgnoreCase("§5§lGas")) {
  272. if (items.getItemMeta().hasLore()) {
  273. ItemMeta meta = items.getItemMeta();
  274. int gasValue = Integer.valueOf(meta.getLore().get(0).split("§5")[2]);
  275. gas.add(gasValue);
  276. }
  277. }
  278. }
  279. }
  280.  
  281. gas.sort(Comparator.naturalOrder());
  282.  
  283. for (ItemStack items : p.getInventory().getContents()) {
  284. if (items != null) {
  285. if (items.getItemMeta().getDisplayName().equalsIgnoreCase("§5§lGas")) {
  286. if (items.getItemMeta().hasLore()) {
  287. ItemMeta meta = items.getItemMeta();
  288. int gasValue = Integer.valueOf(meta.getLore().get(0).split("§5")[2]);
  289.  
  290. if (gasValue == gas.get(0)) {
  291. if (items.getItemMeta().hasLore()) {
  292. if (gasValue > 0) {
  293. gasValue -= distance;
  294. meta.setLore(Arrays.asList("§5§lGas: §5" + gasValue + "§lL"));
  295. items.setItemMeta(meta);
  296.  
  297. p.setVelocity(v.normalize().multiply(boost));
  298. } else {
  299. meta.setLore(Arrays.asList("§5§lGas: §50§lL"));
  300. items.setItemMeta(meta);
  301. p.sendTitle("§5Gas","§0x §cEMTY §0x");
  302. p.sendMessage("§0x §cYou need Gas! §0x");
  303. return;
  304. }
  305. }
  306. }
  307. }
  308. }
  309. }
  310. }
  311. } else {
  312. p.sendTitle("§5Gas","§0x §cLEER §0x");
  313. p.sendMessage("§0x §cDu hast kein Gas! §0x");
  314. }
  315. }
  316.  
  317. @EventHandler
  318. public void onChangeWorld(PlayerChangedWorldEvent e) {
  319. Player p = e.getPlayer();
  320. if(throwed.contains(p)) {
  321. throwed.remove(p);
  322. }
  323. if(thrownOnEntity.containsKey(p)) {
  324. Location loc = thrownOnEntity.get(p).getLocation();
  325.  
  326. for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
  327. LivingEntity livingEntity = (LivingEntity) ent;
  328. livingEntity.setLeashHolder(null);
  329. destroyCable(p, loc);
  330. thrownOnEntity.remove(p);
  331. }
  332. }
  333. if(thrownOnBlock.containsKey(p)) {
  334. Location loc = thrownOnBlock.get(p);
  335. destroyCable(p, loc);
  336. thrownOnBlock.remove(p);
  337. }
  338.  
  339. }
  340.  
  341. private static void destroyCable(Player p, Location loc) {
  342. Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
  343. @Override
  344. public void run() {
  345. for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
  346. if (ent.getType().equals(EntityType.DROPPED_ITEM)) {
  347. Item item = (Item) ent;
  348.  
  349. if (item.getItemStack().getType().equals(Material.LEAD)) {
  350. ent.remove();
  351.  
  352. throwed.remove(p);
  353. thrownOnBlock.remove(p);
  354. thrownOnEntity.remove(p);
  355. }
  356. }
  357. }
  358. }
  359. }, 1);
  360. }
  361. }
Advertisement
RAW Paste Data Copied
Advertisement