Spectator arrow blocking

Discussion in 'Plugin Development' started by Funergy, Oct 4, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Funergy

    So I've seen some threads about this but they didn't help me.
    But what my problem is. Spectators are blocking arrows. Are there ways to fix it? if yes please tell me
     
  2. Funergy If a spectator is hit by an arrow, move them out of the way, and recreate an arrow with the same velocity.
     
  3. Offline

    Funergy

    AdamQpzm I've already tried that and it didn't work
    Code:
    @EventHandler
    public void onPlayerHurtPlayer(EntityDamageByEntityEvent event) {
        Entity entityDamager = event.getDamager();
        Entity entityDamaged = event.getEntity();
     
        if(entityDamager instanceof Arrow) {
            if(entityDamaged instanceof Player && ((Arrow) entityDamager).getShooter() instanceof Player) {
                Arrow arrow = (Arrow) entityDamager;
     
                Vector velocity = arrow.getVelocity();
     
                Player shooter = (Player) arrow.getShooter();
                Player damaged = (Player) entityDamaged;
     
                if(BGMain.isSpectator(damaged)) {
                    damaged.teleport(entityDamaged.getLocation().add(0, 5, 0));
                    damaged.setFlying(true);
               
                    Arrow newArrow = shooter.launchProjectile(Arrow.class);
                    newArrow.setShooter(shooter);
                    newArrow.setVelocity(velocity);
                    newArrow.setBounce(false);
               
                    event.setCancelled(true);
                    arrow.remove();
                }
            }
        }
    }
     
  4. Offline

    CaptainUniverse

    Funergy why are you checking if the shooter is a player?
     
  5. Offline

    xepisolonxx

    Funergy When someone shoots check all you spectators and check nearby entities and check if the entity is an arrow.
     
  6. Offline

    Funergy

    CaptainUniverse It could be a skeleton

    xepisolonxx I've seen on some servers that it just goes through someone without teleporting

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  7. Offline

    thomasb454

    I believe this is done via a custom build of Bukkit/Spigot.
     
  8. Offline

    CraftCreeper6

    Doesn't p#hidePlayer(); work?
     
  9. Offline

    xepisolonxx

    Funergy Then if bukkit goes to 1.8 ill recommended spectator mode.
     
  10. Offline

    Funergy

  11. Offline

    RingOfStorms

    Create a custom class for arrows that has custom collision detection and then inject it into the server replacing the default arrow class.
     
Thread Status:
Not open for further replies.

Share This Page