Created
July 4, 2014 13:39
-
-
Save NeatMonster/fff2cabff7e106387bf0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package fr.neatmonster.arrows; | |
| import org.bukkit.block.Block; | |
| import org.bukkit.block.BlockFace; | |
| import org.bukkit.entity.Arrow; | |
| import org.bukkit.entity.EntityType; | |
| import org.bukkit.event.EventHandler; | |
| import org.bukkit.event.Listener; | |
| import org.bukkit.event.entity.ProjectileHitEvent; | |
| import org.bukkit.plugin.java.JavaPlugin; | |
| import org.bukkit.util.BlockIterator; | |
| import org.bukkit.util.Vector; | |
| public class Arrows extends JavaPlugin implements Listener { | |
| @Override | |
| public void onEnable() { | |
| getServer().getPluginManager().registerEvents(this, this); | |
| } | |
| @EventHandler | |
| public void onProjectileHit(final ProjectileHitEvent event) { | |
| if (event.getEntityType() == EntityType.ARROW) { | |
| final Arrow arrow = (Arrow) event.getEntity(); | |
| if (arrow.getVelocity().length() > 0.5D) { | |
| final BlockIterator path = new BlockIterator(arrow.getWorld(), arrow.getLocation().toVector(), arrow.getVelocity(), 0, 3); | |
| Block next = path.next(); | |
| Block previous = arrow.getLocation().getBlock(); | |
| while (path.hasNext() && !next.getType().isSolid()) { | |
| previous = next; | |
| next = path.next(); | |
| } | |
| final BlockFace face = next.getFace(previous); | |
| final Vector velocity = arrow.getVelocity().clone(); | |
| if (Math.abs(face.getModX()) > 0D) | |
| velocity.setX(-1D * velocity.getX()); | |
| if (Math.abs(face.getModY()) > 0D) | |
| velocity.setY(-1D * velocity.getY()); | |
| if (Math.abs(face.getModZ()) > 0D) | |
| velocity.setZ(-1D * velocity.getZ()); | |
| arrow.getWorld().spawnArrow(arrow.getLocation(), velocity, (float) arrow.getVelocity().length() * 0.6f, 0f); | |
| arrow.remove(); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Arrows | |
| version: 1.0 | |
| author: NeatMonster | |
| main: fr.neatmonster.arrows.Arrows |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment