Created
August 29, 2014 19:58
-
-
Save DarkSeraphim/4615662cdeab9c7c756e to your computer and use it in GitHub Desktop.
Riding projectiles in Minecraft.
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
| /** | |
| * | |
| * Do note: only Arrow and ThrownExpBottle work with this method. | |
| * The rest was just testing material. | |
| * | |
| **/ | |
| Team team; | |
| @CommandHandler(name = "testcommand") | |
| public boolean test(CommandSender sender, String label, String[] args) | |
| { | |
| if(sender instanceof Player) | |
| { | |
| Player player = (Player) sender; | |
| Scoreboard sb = player.getScoreboard(); | |
| team = sb.registerNewTeam(player.getName()); | |
| team.addPlayer(player); | |
| team.setAllowFriendlyFire(false); | |
| Class<? extends Projectile> clazz = Arrow.class; | |
| if(args.length > 0) | |
| if(args[0].equalsIgnoreCase("ep")) | |
| clazz = EnderPearl.class; | |
| else if(args[0].equalsIgnoreCase("sb")) | |
| clazz = Snowball.class; | |
| else if(args[0].equalsIgnoreCase("egg")) | |
| clazz = Egg.class; | |
| else if(args[0].equalsIgnoreCase("exp")) | |
| clazz = ThrownExpBottle.class; | |
| Projectile arrow = player.launchProjectile(clazz); | |
| if(clazz == EnderPearl.class || clazz == Snowball.class || clazz == Egg.class) | |
| { | |
| Projectile ws = player.getWorld().spawn(player.getLocation(), WitherSkull.class); | |
| arrow.setPassenger(ws); | |
| arrow = ws; | |
| } | |
| arrow.setPassenger(player); | |
| } | |
| return true; | |
| } | |
| @EventHandler | |
| public void on(ProjectileHitEvent event) | |
| { | |
| ProjectileSource source = event.getEntity().getShooter(); | |
| if(source instanceof Player) | |
| { | |
| team.removePlayer((Player)source); | |
| team.unregister(); | |
| Entity passenger = event.getEntity().getPassenger(); | |
| event.getEntity().remove(); | |
| if(passenger instanceof WitherSkull) | |
| { | |
| passenger.eject(); | |
| passenger.remove(); | |
| } | |
| event.getEntity().remove(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment