hassansyyid

Untitled

Jul 16th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 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. import com.google.common.base.Optional;
  19.  
  20. public class JumpExecutor implements CommandExecutor
  21. {
  22.     public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
  23.     {
  24.         if(src instanceof Player)
  25.         {
  26.             Player player = (Player) src;
  27.             BlockRayBuilder blockRayBuilder = BlockRay.from(player);
  28.             BlockRay ray = blockRayBuilder.filter(BlockRay.ONLY_AIR_FILTER).blockLimit(50).build();
  29.             Optional<BlockRayHit> end = ray.end();
  30.             BlockRayHit hit = end.get();
  31.             Location location = new Location(player.getWorld(), hit.getBlockX(), hit.getBlockY(), hit.getBlockZ());
  32.             player.setLocation(location);
  33.         }
  34.         else if(src instanceof ConsoleSource) {
  35.             src.sendMessage(Texts.of(TextColors.DARK_RED,"Error! ", TextColors.RED, "Must be an in-game player to use /jump!"));
  36.         }
  37.         else if(src instanceof CommandBlockSource) {
  38.             src.sendMessage(Texts.of(TextColors.DARK_RED,"Error! ", TextColors.RED, "Must be an in-game player to use /jump!"));
  39.         }
  40.         return CommandResult.success();
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment