Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MAIN
- import org.bukkit.Bukkit;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin{
- private static Main instance;
- @Override
- public void onEnable() {
- PluginManager pm = Bukkit.getPluginManager();
- pm.registerEvents(new ManeuvergearListener(), this);
- super.onEnable();
- }
- public static Main getInstance() {
- return instance;
- }
- }
- //LISTENER
- import org.bukkit.Bukkit;
- import org.bukkit.GameMode;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.craftbukkit.v1_16_R3.entity.CraftBat;
- import org.bukkit.entity.*;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.Action;
- import org.bukkit.event.entity.EntityUnleashEvent;
- import org.bukkit.event.entity.PlayerDeathEvent;
- import org.bukkit.event.entity.ProjectileHitEvent;
- import org.bukkit.event.player.PlayerChangedWorldEvent;
- import org.bukkit.event.player.PlayerGameModeChangeEvent;
- import org.bukkit.event.player.PlayerInteractEntityEvent;
- import org.bukkit.event.player.PlayerInteractEvent;
- import org.bukkit.event.player.PlayerToggleFlightEvent;
- import org.bukkit.inventory.EquipmentSlot;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.util.Vector;
- import java.util.*;
- public class ManeuvergearListener implements Listener {
- private static ArrayList<Player> throwed = new ArrayList<>();
- private static HashMap<Player, Location> thrownOnBlock = new HashMap<>();
- private static HashMap<Player, LivingEntity> thrownOnEntity = new HashMap<>();
- private static int boost = 2;
- private static int distance = 60;
- @EventHandler
- private void onThrow(PlayerInteractEvent e) {
- if (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
- if (e.getHand().equals(EquipmentSlot.HAND)) {
- if (e.getPlayer().getInventory().getItemInMainHand().hasItemMeta() && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().getDisplayName().equalsIgnoreCase("§l3D MANEUVER GEAR")) {
- Player p = e.getPlayer();
- if (p.getGameMode() != GameMode.CREATIVE) {
- if (!throwed.contains(p)) {
- throwed.add(p);
- p.launchProjectile(Arrow.class);
- Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
- @Override
- public void run() {
- if (!thrownOnBlock.containsKey(p) && !thrownOnEntity.containsKey(p)) {
- throwed.remove(p);
- }
- }
- }, 20 * 10);
- } else {
- if (thrownOnBlock.containsKey(p)) {
- boostPlayer(p, thrownOnBlock.get(p));
- } else if (thrownOnEntity.containsKey(p)) {
- boostPlayer(p, thrownOnEntity.get(p).getLocation());
- }
- }
- }
- }
- }
- }
- }
- @EventHandler
- public void onDeath(PlayerDeathEvent e) {
- Player p = e.getEntity().getPlayer();
- if(throwed.contains(p)) {
- throwed.remove(p);
- }
- if(thrownOnEntity.containsKey(p)) {
- Location loc = thrownOnEntity.get(p).getLocation();
- for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
- LivingEntity livingEntity = (LivingEntity) ent;
- livingEntity.setLeashHolder(null);
- destroyCable(p, loc);
- thrownOnEntity.remove(p);
- }
- }
- if(thrownOnBlock.containsKey(p)) {
- Location loc = thrownOnBlock.get(p);
- for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
- LivingEntity livingEntity = (LivingEntity) ent;
- livingEntity.setLeashHolder(null);
- destroyCable(p, loc);
- thrownOnBlock.remove(p);
- }
- }
- }
- @EventHandler
- public void onGameModeChange(PlayerGameModeChangeEvent e) {
- Player p = e.getPlayer();
- if(throwed.contains(p)) {
- throwed.remove(p);
- }
- if(thrownOnEntity.containsKey(p)) {
- Location loc = thrownOnEntity.get(p).getLocation();
- for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
- LivingEntity livingEntity = (LivingEntity) ent;
- livingEntity.setLeashHolder(null);
- destroyCable(p, loc);
- thrownOnEntity.remove(p);
- }
- }
- if(thrownOnBlock.containsKey(p)) {
- Location loc = thrownOnBlock.get(p);
- for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
- LivingEntity livingEntity = (LivingEntity) ent;
- livingEntity.setLeashHolder(null);
- destroyCable(p, loc);
- thrownOnBlock.remove(p);
- }
- }
- }
- @EventHandler
- private void onHit(ProjectileHitEvent e) {
- if (e.getEntity().getShooter() instanceof Player) {
- Player p = (Player) e.getEntity().getShooter();
- if (!thrownOnBlock.containsKey(p) && !thrownOnEntity.containsKey(p)) {
- Arrow arrow = (Arrow) e.getEntity();
- if (e.getHitBlock() != null && e.getHitEntity() == null) {
- if (!(p.getLocation().distance(e.getHitBlock().getLocation()) >= distance)) {
- thrownOnBlock.put(p, e.getHitBlock().getLocation());
- Bat bat = p.getWorld().spawn(e.getHitBlock().getLocation(), Bat.class);
- bat.setAI(false);
- bat.setSilent(true);
- bat.setInvisible(true);
- bat.setInvulnerable(true);
- bat.setLeashHolder(p);
- p.setAllowFlight(true);
- } else {
- throwed.remove(p);
- }
- } else if (e.getHitEntity() != null && e.getHitBlock() == null) {
- if (!(p.getLocation().distance(e.getHitEntity().getLocation()) >= distance)) {
- LivingEntity entity = (LivingEntity) e.getHitEntity();
- entity.setLeashHolder(p);
- thrownOnEntity.put(p, entity);
- p.setAllowFlight(true);
- } else {
- throwed.remove(p);
- }
- }
- arrow.remove();
- }
- }
- }
- @EventHandler
- private void onUnleash(EntityUnleashEvent e) {
- LivingEntity livingEntity = (LivingEntity) e.getEntity();
- if (livingEntity.getLeashHolder() instanceof Player) {
- Player p = (Player) livingEntity.getLeashHolder();
- if (thrownOnBlock.containsKey(p) || thrownOnEntity.containsKey(p)) {
- destroyCable(p, livingEntity.getLocation());
- }
- }
- }
- @EventHandler
- public void onFlightAttempt(PlayerToggleFlightEvent e) {
- Player p = e.getPlayer();
- if ((p.getGameMode() != GameMode.CREATIVE) && (p.getAllowFlight())) {
- e.setCancelled(true);
- p.setAllowFlight(false);
- p.setFlying(false);
- if (thrownOnBlock.containsKey(p)) {
- Location loc = thrownOnBlock.get(p);
- for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
- LivingEntity livingEntity = (LivingEntity) ent;
- if (ent instanceof CraftBat) {
- livingEntity.setHealth(0);
- }
- }
- destroyCable(p, loc);
- } else if (thrownOnEntity.containsKey(p)) {
- Location loc = thrownOnEntity.get(p).getLocation();
- for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
- LivingEntity livingEntity = (LivingEntity) ent;
- livingEntity.setLeashHolder(null);
- throwed.remove(p);
- thrownOnBlock.remove(p);
- thrownOnEntity.remove(p);
- }
- }
- }
- }
- @EventHandler
- private void onInteract(PlayerInteractEntityEvent e) {
- Player p = e.getPlayer();
- if (thrownOnEntity.containsKey(p)) {
- LivingEntity rightclicked = (LivingEntity) e.getRightClicked();
- LivingEntity entity = thrownOnEntity.get(e.getPlayer());
- if (rightclicked.equals(entity)) {
- e.setCancelled(true);
- boostPlayer(p, thrownOnEntity.get(p).getLocation());
- }
- } else {
- if (e.getRightClicked() instanceof CraftBat) {
- e.setCancelled(true);
- boostPlayer(p, thrownOnBlock.get(p));
- }
- }
- }
- private static void boostPlayer(Player p, Location to) {
- Vector v = to.toVector().subtract(p.getLocation().toVector());
- long distance = Math.round(p.getLocation().distance(to) * 100) / 100;
- List<Integer> gas = new ArrayList<>();
- if (p.getInventory().contains(Material.POTION)) {
- for (ItemStack items : p.getInventory().getContents()) {
- if (items != null) {
- if (items.getItemMeta().getDisplayName().equalsIgnoreCase("§5§lGas")) {
- if (items.getItemMeta().hasLore()) {
- ItemMeta meta = items.getItemMeta();
- int gasValue = Integer.valueOf(meta.getLore().get(0).split("§5")[2]);
- gas.add(gasValue);
- }
- }
- }
- }
- gas.sort(Comparator.naturalOrder());
- for (ItemStack items : p.getInventory().getContents()) {
- if (items != null) {
- if (items.getItemMeta().getDisplayName().equalsIgnoreCase("§5§lGas")) {
- if (items.getItemMeta().hasLore()) {
- ItemMeta meta = items.getItemMeta();
- int gasValue = Integer.valueOf(meta.getLore().get(0).split("§5")[2]);
- if (gasValue == gas.get(0)) {
- if (items.getItemMeta().hasLore()) {
- if (gasValue > 0) {
- gasValue -= distance;
- meta.setLore(Arrays.asList("§5§lGas: §5" + gasValue + "§lL"));
- items.setItemMeta(meta);
- p.setVelocity(v.normalize().multiply(boost));
- } else {
- meta.setLore(Arrays.asList("§5§lGas: §50§lL"));
- items.setItemMeta(meta);
- p.sendTitle("§5Gas","§0x §cEMTY §0x");
- p.sendMessage("§0x §cYou need Gas! §0x");
- return;
- }
- }
- }
- }
- }
- }
- }
- } else {
- p.sendTitle("§5Gas","§0x §cLEER §0x");
- p.sendMessage("§0x §cDu hast kein Gas! §0x");
- }
- }
- @EventHandler
- public void onChangeWorld(PlayerChangedWorldEvent e) {
- Player p = e.getPlayer();
- if(throwed.contains(p)) {
- throwed.remove(p);
- }
- if(thrownOnEntity.containsKey(p)) {
- Location loc = thrownOnEntity.get(p).getLocation();
- for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
- LivingEntity livingEntity = (LivingEntity) ent;
- livingEntity.setLeashHolder(null);
- destroyCable(p, loc);
- thrownOnEntity.remove(p);
- }
- }
- if(thrownOnBlock.containsKey(p)) {
- Location loc = thrownOnBlock.get(p);
- destroyCable(p, loc);
- thrownOnBlock.remove(p);
- }
- }
- private static void destroyCable(Player p, Location loc) {
- Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), new Runnable() {
- @Override
- public void run() {
- for (Entity ent : p.getWorld().getNearbyEntities(loc, 1, 1, 1)) {
- if (ent.getType().equals(EntityType.DROPPED_ITEM)) {
- Item item = (Item) ent;
- if (item.getItemStack().getType().equals(Material.LEAD)) {
- ent.remove();
- throwed.remove(p);
- thrownOnBlock.remove(p);
- thrownOnEntity.remove(p);
- }
- }
- }
- }
- }, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement