hassansyyid

Untitled

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