hassansyyid

Untitled

Aug 18th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.30 KB | None | 0 0
  1. package io.github.hsyyid.spongeessentialcmds.cmdexecutors;
  2.  
  3. import com.google.common.base.Optional;
  4. import org.spongepowered.api.entity.Entity;
  5. import org.spongepowered.api.entity.EntityTypes;
  6. import org.spongepowered.api.entity.player.Player;
  7. import org.spongepowered.api.text.Texts;
  8. import org.spongepowered.api.text.format.TextColors;
  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.extent.Extent;
  18.  
  19. public class LightningExecutor 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.             Location playerLocation = player.getLocation();
  27.             Location lightningLocation = new Location(playerLocation.getExtent(), playerLocation.getX() + 5, playerLocation.getY(), playerLocation.getZ());
  28.             spawnEntity(lightningLocation);
  29.             player.sendMessage(Texts.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Created Lightning Strike!"));
  30.         }
  31.         else if(src instanceof ConsoleSource) {
  32.             src.sendMessage(Texts.of(TextColors.DARK_RED,"Error! ", TextColors.RED, "Must be an in-game player to use /lightning!"));
  33.         }
  34.         else if(src instanceof CommandBlockSource) {
  35.             src.sendMessage(Texts.of(TextColors.DARK_RED,"Error! ", TextColors.RED, "Must be an in-game player to use /lightning!"));
  36.         }
  37.         return CommandResult.success();
  38.     }
  39.    
  40.     public void spawnEntity(Location location)
  41.     {
  42.         Extent extent = location.getExtent();
  43.         Optional<Entity> optional = extent.createEntity(EntityTypes.LIGHTNING, location.getPosition());
  44.  
  45.         if (optional.isPresent())
  46.         {
  47.             Entity lightning = optional.get();
  48.             extent.spawnEntity(lightning);
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment