hassansyyid

Untitled

Jul 16th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.81 KB | None | 0 0
  1. package io.github.hsyyid.home;
  2.  
  3. import org.spongepowered.api.entity.player.Player;
  4. import org.spongepowered.api.text.Texts;
  5. import org.spongepowered.api.text.format.TextColors;
  6. import org.spongepowered.api.util.blockray.BlockRay;
  7. import org.spongepowered.api.util.blockray.BlockRay.BlockRayBuilder;
  8. import org.spongepowered.api.util.blockray.BlockRayHit;
  9. import org.spongepowered.api.util.command.CommandException;
  10. import org.spongepowered.api.util.command.CommandResult;
  11. import org.spongepowered.api.util.command.CommandSource;
  12. import org.spongepowered.api.util.command.args.CommandContext;
  13. import org.spongepowered.api.util.command.source.CommandBlockSource;
  14. import org.spongepowered.api.util.command.source.ConsoleSource;
  15. import org.spongepowered.api.util.command.spec.CommandExecutor;
  16. import org.spongepowered.api.world.Location;
  17.  
  18. public class JumpExecutor implements CommandExecutor
  19. {
  20.     public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
  21.     {
  22.         if(src instanceof Player)
  23.         {
  24.             Player player = (Player) src;
  25.             BlockRayBuilder blockRayBuilder = BlockRay.from(player);
  26.             BlockRay ray = blockRayBuilder.filter(BlockRay.ONLY_AIR_FILTER).blockLimit(30).build();
  27.             BlockRayHit hit = ray.end().get();
  28.             if(ray.hasNext())
  29.             {
  30.                 hit = ray.next();
  31.             }
  32.             Location location = new Location(player.getWorld(), hit.getBlockX(), hit.getBlockY(), hit.getBlockZ());
  33.             player.setLocation(location);
  34.         }
  35.         else if(src instanceof ConsoleSource) {
  36.             src.sendMessage(Texts.of(TextColors.DARK_RED,"Error! ", TextColors.RED, "Must be an in-game player to use /jump!"));
  37.         }
  38.         else if(src instanceof CommandBlockSource) {
  39.             src.sendMessage(Texts.of(TextColors.DARK_RED,"Error! ", TextColors.RED, "Must be an in-game player to use /jump!"));
  40.         }
  41.         return CommandResult.success();
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment