hassansyyid

Untitled

Aug 2nd, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. package io.github.hsyyid.itemauction.cmdexecutors;
  2.  
  3. import io.github.hsyyid.itemauction.Main;
  4.  
  5. import org.spongepowered.api.Game;
  6. import org.spongepowered.api.Server;
  7. import org.spongepowered.api.entity.player.Player;
  8. import org.spongepowered.api.item.inventory.ItemStack;
  9. import org.spongepowered.api.text.Texts;
  10. import org.spongepowered.api.text.format.TextColors;
  11. import org.spongepowered.api.util.command.CommandException;
  12. import org.spongepowered.api.util.command.CommandResult;
  13. import org.spongepowered.api.util.command.CommandSource;
  14. import org.spongepowered.api.util.command.args.CommandContext;
  15. import org.spongepowered.api.util.command.source.CommandBlockSource;
  16. import org.spongepowered.api.util.command.source.ConsoleSource;
  17. import org.spongepowered.api.util.command.spec.CommandExecutor;
  18.  
  19. import com.google.common.base.Optional;
  20.  
  21. public class AuctionExecutor implements CommandExecutor
  22. {
  23.     public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
  24.     {
  25.         Game game = Main.game;
  26.         Server server = game.getServer();
  27.         int price = ctx.<Integer> getOne("price").get();
  28.         if (src instanceof Player)
  29.         {
  30.             Player player = (Player) src;
  31.             Optional<ItemStack> optionalItemInHand = player.getItemInHand();
  32.             ItemStack itemInHand = null;
  33.             if (optionalItemInHand != Optional.<ItemStack> absent())
  34.             {
  35.                 itemInHand = optionalItemInHand.get();
  36.                 for(Player p : server.getOnlinePlayers())
  37.                 {
  38.                     p.sendMessage(Texts.of(TextColors.GREEN, "[ItemAuction] ", TextColors.YELLOW, player.getName(), TextColors.WHITE, " is now auctioning " + itemInHand.getQuantity() + " " + itemInHand.getItem().getTranslation() + " for " + price + " dollars."));
  39.                 }
  40.             }
  41.             else
  42.             {
  43.                 src.sendMessage(Texts.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You aren't holding anything!"));
  44.                 return CommandResult.success();
  45.             }
  46.         }
  47.         else if (src instanceof ConsoleSource)
  48.         {
  49.             src.sendMessage(Texts.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /auction!"));
  50.         }
  51.         else if (src instanceof CommandBlockSource)
  52.         {
  53.             src.sendMessage(Texts.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Must be an in-game player to use /auction!"));
  54.         }
  55.  
  56.         return CommandResult.success();
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment