Advertisement
AlexanderNorup

Sponge Example Command

May 9th, 2015
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. package com.projectstrafe.SpongeEssentials.Commands;
  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.command.CommandException;
  7. import org.spongepowered.api.util.command.CommandResult;
  8. import org.spongepowered.api.util.command.CommandSource;
  9. import org.spongepowered.api.util.command.args.CommandContext;
  10. import org.spongepowered.api.util.command.spec.CommandExecutor;
  11.  
  12.  
  13. public class ClassName implements CommandExecutor {
  14.  
  15.     private MAINCLASS plugin; // You can delete these four lines, if you don't want to access the main class
  16.     public ClassName(MAINCLASS plugin) {
  17.         this.plugin = plugin;
  18.     }
  19.  
  20.     @Override
  21.     public CommandResult execute(CommandSource src, CommandContext args)
  22.             throws CommandException {
  23.         if (src instanceof Player) { // Check if sender is player
  24.             Player p = (Player) src; // Parse sender  to player.
  25.            
  26.             // DO STUFF WITH PLAYER HERE!
  27.  
  28.         } else {
  29.             src.sendMessage(Texts.of("Only players can execute this command")); //IF not player!
  30.         }
  31.  
  32.         return CommandResult.success(); //Return success!
  33.     }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement