Skip to content

Instantly share code, notes, and snippets.

Created April 30, 2015 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/649afc6f77bc13c3198b to your computer and use it in GitHub Desktop.
Save anonymous/649afc6f77bc13c3198b to your computer and use it in GitHub Desktop.
package me.impervious.test.Commands;
import java.util.List;
import org.spongepowered.api.Game;
import org.spongepowered.api.data.manipulators.PotionEffectData;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.potion.PotionEffect;
import org.spongepowered.api.potion.PotionEffectBuilder;
import org.spongepowered.api.potion.PotionEffectTypes;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.Texts;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.util.command.CommandCallable;
import org.spongepowered.api.util.command.CommandException;
import org.spongepowered.api.util.command.CommandResult;
import org.spongepowered.api.util.command.CommandSource;
import com.google.common.base.Optional;
public class ConfuseCommand implements CommandCallable {
Game game;
public ConfuseCommand(Game game) {
this.game = game;
}
public boolean testPermission(CommandSource source) {
return source.hasPermission("troll.confuse");
}
public Optional<Text> getShortDescription(CommandSource source) {
return Optional.of((Text) Texts.of("Confuses the target"));
}
public Optional<Text> getHelp(CommandSource source) {
return Optional.of((Text) Texts.of("Confuses thetarget with multiple potion effects"));
}
public Text getUsage(CommandSource source) {
return Texts.of("/confuse <target>");
}
public Optional<CommandResult> process(CommandSource source, String args) throws CommandException {
PotionEffectBuilder builder = game.getRegistry().getBuilderOf(PotionEffectBuilder.class).get();
PotionEffect effect = builder.potionType(PotionEffectTypes.SPEED).build();
if(source instanceof Player) {
final Player player = (Player) source;
if(args.length() > 1) {
player.sendMessage(Texts.of(TextColors.RED, "Incorrect Syntax: /confuse <target>"));
} else if(args.length() == 0) {
player.sendMessage(Texts.of(TextColors.RED, "Incorrect Syntax: /confuse <target>"));
} else if(args.length() == 1) {
PotionEffectData effectData = (PotionEffectData) player.getOrCreate(PotionEffectData.class);
effectData.addPotionEffect(effect, true);
player.offer(effectData);
}
}
return Optional.of(CommandResult.success());
}
public List<String> getSuggestions(CommandSource source, String args) throws CommandException {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment