mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-08 19:34:09 +01:00
Add Effect command. Adds BUKKIT-3763
By: feildmaster <admin@feildmaster.com>
This commit is contained in:
parent
423cccdc8d
commit
071c599044
3 changed files with 113 additions and 1 deletions
|
@ -56,6 +56,7 @@ public class SimpleCommandMap implements CommandMap {
|
|||
fallbackCommands.add(new GameRuleCommand());
|
||||
fallbackCommands.add(new EnchantCommand());
|
||||
fallbackCommands.add(new TestForCommand());
|
||||
fallbackCommands.add(new EffectCommand());
|
||||
}
|
||||
|
||||
public SimpleCommandMap(final Server server) {
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
package org.bukkit.command.defaults;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
public class EffectCommand extends VanillaCommand {
|
||||
private static final List<String> effects;
|
||||
|
||||
public EffectCommand() {
|
||||
super("effect");
|
||||
this.description = "Adds/Removes effects on players";
|
||||
this.usageMessage = "/effect <player> <effect> [seconds] [amplifier]";
|
||||
this.setPermission("bukkit.command.effect");
|
||||
}
|
||||
|
||||
static {
|
||||
ImmutableList.Builder<String> builder = ImmutableList.<String>builder();
|
||||
|
||||
for (PotionEffectType type : PotionEffectType.values()) {
|
||||
if (type != null) {
|
||||
builder.add(type.getName());
|
||||
}
|
||||
}
|
||||
|
||||
effects = builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (!testPermission(sender)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(getUsage());
|
||||
return true;
|
||||
}
|
||||
|
||||
final Player player = sender.getServer().getPlayer(args[0]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(ChatColor.RED + String.format("Player, %s, not found", args[0]));
|
||||
return true;
|
||||
}
|
||||
|
||||
PotionEffectType effect = PotionEffectType.getByName(args[1]);
|
||||
|
||||
if (effect == null) {
|
||||
effect = PotionEffectType.getById(getInteger(sender, args[1], 0));
|
||||
}
|
||||
|
||||
if (effect == null) {
|
||||
sender.sendMessage(ChatColor.RED + String.format("Effect, %s, not found", args[1]));
|
||||
return true;
|
||||
}
|
||||
|
||||
int duration = 600;
|
||||
int duration_temp = 30;
|
||||
int amplification = 0;
|
||||
|
||||
if (args.length >= 3) {
|
||||
duration_temp = getInteger(sender, args[2], 0, 1000000);
|
||||
if (effect.isInstant()) {
|
||||
duration = duration_temp;
|
||||
} else {
|
||||
duration = duration_temp * 20;
|
||||
}
|
||||
} else if (effect.isInstant()) {
|
||||
duration = 1;
|
||||
}
|
||||
|
||||
if (args.length >= 4) {
|
||||
amplification = getInteger(sender, args[3], 0, 255);
|
||||
}
|
||||
|
||||
if (duration_temp == 0) {
|
||||
if (!player.hasPotionEffect(effect)) {
|
||||
sender.sendMessage(String.format("Couldn't take %s from %s as they do not have the effect", effect.getName(), args[0]));
|
||||
return true;
|
||||
}
|
||||
|
||||
player.removePotionEffect(effect);
|
||||
broadcastCommandMessage(sender, String.format("Took %s from %s", effect.getName(), args[0]));
|
||||
} else {
|
||||
final PotionEffect applyEffect = new PotionEffect(effect, duration, amplification);
|
||||
|
||||
player.addPotionEffect(applyEffect, true);
|
||||
broadcastCommandMessage(sender, String.format("Given %s (ID %d) * %d to %s for %d seconds", effect.getName(), effect.getId(), amplification, args[0], duration));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String commandLabel, String[] args) {
|
||||
if (args.length == 1) {
|
||||
return super.tabComplete(sender, commandLabel, args);
|
||||
} else if (args.length == 2) {
|
||||
return StringUtil.copyPartialMatches(args[1], effects, new ArrayList<String>(effects.size()));
|
||||
}
|
||||
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
|
@ -108,7 +108,7 @@ public final class CommandPermissions {
|
|||
DefaultPermissions.registerPermission(PREFIX + "toggledownfall", "Allows the user to toggle rain on/off for a given world", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "defaultgamemode", "Allows the user to change the default gamemode of the server", PermissionDefault.OP, commands);
|
||||
DefaultPermissions.registerPermission(PREFIX + "seed", "Allows the user to view the seed of the world", PermissionDefault.OP, commands);
|
||||
|
||||
DefaultPermissions.registerPermission(PREFIX + "effect", "Allows the user to add/remove effects on players", PermissionDefault.OP, commands);
|
||||
|
||||
commands.recalculatePermissibles();
|
||||
|
||||
|
|
Loading…
Reference in a new issue