Potion effect arguments
The PotionEffectArgument
class represents Minecraft potion effects. When used, this argument is casted to Bukkit's PotionEffectType
class.
Example - Giving a player a potion effect
Say we wanted to have a command that gives a player a potion effect. For this command, we'll use the following syntax:
/potion <target> <potion> <duration> <strength>
In this example, we utilize some of the other arguments that we've described earlier, such as the PlayerArgument
and TimeArgument
. Since duration for the PotionEffect
constructor is in ticks, this is perfectly fit for the TimeArgument
, which is represented in ticks.
new CommandAPICommand("potion")
.withArguments(new PlayerArgument("target"))
.withArguments(new PotionEffectArgument("potion"))
.withArguments(new TimeArgument("duration"))
.withArguments(new IntegerArgument("strength"))
.executes((sender, args) -> {
Player target = (Player) args[0];
PotionEffectType potion = (PotionEffectType) args[1];
int duration = (int) args[2];
int strength = (int) args[3];
// Add the potion effect to the target player
target.addPotionEffect(new PotionEffect(potion, duration, strength));
})
.register();
CommandAPICommand("potion")
.withArguments(PlayerArgument("target"))
.withArguments(PotionEffectArgument("potion"))
.withArguments(TimeArgument("duration"))
.withArguments(IntegerArgument("strength"))
.executes(CommandExecutor { _, args ->
val target = args[0] as Player
val potion = args[1] as PotionEffectType
val duration = args[2] as Int
val strength = args[3] as Int
// Add the potion effect to the target player
target.addPotionEffect(PotionEffect(potion, duration, strength))
})
.register()