001package net.minecraft.command; 002 003import java.util.List; 004import net.minecraft.entity.player.EntityPlayerMP; 005import net.minecraft.potion.Potion; 006import net.minecraft.potion.PotionEffect; 007import net.minecraft.server.MinecraftServer; 008import net.minecraft.util.StatCollector; 009 010public class CommandEffect extends CommandBase 011{ 012 public String getCommandName() 013 { 014 return "effect"; 015 } 016 017 /** 018 * Return the required permission level for this command. 019 */ 020 public int getRequiredPermissionLevel() 021 { 022 return 2; 023 } 024 025 public String getCommandUsage(ICommandSender par1ICommandSender) 026 { 027 return par1ICommandSender.translateString("commands.effect.usage", new Object[0]); 028 } 029 030 public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr) 031 { 032 if (par2ArrayOfStr.length >= 2) 033 { 034 EntityPlayerMP entityplayermp = func_82359_c(par1ICommandSender, par2ArrayOfStr[0]); 035 int i = parseIntWithMin(par1ICommandSender, par2ArrayOfStr[1], 1); 036 int j = 600; 037 int k = 30; 038 int l = 0; 039 040 if (i >= 0 && i < Potion.potionTypes.length && Potion.potionTypes[i] != null) 041 { 042 if (par2ArrayOfStr.length >= 3) 043 { 044 k = parseIntBounded(par1ICommandSender, par2ArrayOfStr[2], 0, 1000000); 045 046 if (Potion.potionTypes[i].isInstant()) 047 { 048 j = k; 049 } 050 else 051 { 052 j = k * 20; 053 } 054 } 055 else if (Potion.potionTypes[i].isInstant()) 056 { 057 j = 1; 058 } 059 060 if (par2ArrayOfStr.length >= 4) 061 { 062 l = parseIntBounded(par1ICommandSender, par2ArrayOfStr[3], 0, 255); 063 } 064 065 if (k == 0) 066 { 067 if (!entityplayermp.isPotionActive(i)) 068 { 069 throw new CommandException("commands.effect.failure.notActive", new Object[] {StatCollector.translateToLocal(Potion.potionTypes[i].getName()), entityplayermp.getEntityName()}); 070 } 071 072 entityplayermp.removePotionEffect(i); 073 notifyAdmins(par1ICommandSender, "commands.effect.success.removed", new Object[] {StatCollector.translateToLocal(Potion.potionTypes[i].getName()), entityplayermp.getEntityName()}); 074 } 075 else 076 { 077 PotionEffect potioneffect = new PotionEffect(i, j, l); 078 entityplayermp.addPotionEffect(potioneffect); 079 notifyAdmins(par1ICommandSender, "commands.effect.success", new Object[] {StatCollector.translateToLocal(potioneffect.getEffectName()), Integer.valueOf(i), Integer.valueOf(l), entityplayermp.getEntityName(), Integer.valueOf(k)}); 080 } 081 } 082 else 083 { 084 throw new NumberInvalidException("commands.effect.notFound", new Object[] {Integer.valueOf(i)}); 085 } 086 } 087 else 088 { 089 throw new WrongUsageException("commands.effect.usage", new Object[0]); 090 } 091 } 092 093 /** 094 * Adds the strings available in this command to the given list of tab completion options. 095 */ 096 public List addTabCompletionOptions(ICommandSender par1ICommandSender, String[] par2ArrayOfStr) 097 { 098 return par2ArrayOfStr.length == 1 ? getListOfStringsMatchingLastWord(par2ArrayOfStr, this.func_98152_d()) : null; 099 } 100 101 protected String[] func_98152_d() 102 { 103 return MinecraftServer.getServer().getAllUsernames(); 104 } 105 106 /** 107 * Return whether the specified command parameter index is a username parameter. 108 */ 109 public boolean isUsernameIndex(String[] par1ArrayOfStr, int par2) 110 { 111 return par2 == 0; 112 } 113}