11package clashsoft .brewingapi .command ;
22
33import java .util .ArrayList ;
4- import java .util .Arrays ;
54import java .util .List ;
65
76import clashsoft .brewingapi .BrewingAPI ;
7+ import clashsoft .brewingapi .potion .type .IPotionType ;
88import clashsoft .brewingapi .potion .type .PotionType ;
99
1010import net .minecraft .command .CommandBase ;
11+ import net .minecraft .command .CommandNotFoundException ;
1112import net .minecraft .command .ICommandSender ;
1213import net .minecraft .command .NumberInvalidException ;
1314import net .minecraft .entity .item .EntityItem ;
14- import net .minecraft .entity .player .EntityPlayerMP ;
15+ import net .minecraft .entity .player .EntityPlayer ;
1516import net .minecraft .item .ItemStack ;
1617import net .minecraft .potion .Potion ;
1718import net .minecraft .potion .PotionEffect ;
1819import net .minecraft .server .MinecraftServer ;
19- import net .minecraft .util .ChatComponentText ;
2020
2121public class CommandPotion extends CommandBase
2222{
@@ -56,56 +56,82 @@ public String getCommandUsage(ICommandSender sender)
5656 @ Override
5757 public void processCommand (ICommandSender sender , String [] args )
5858 {
59- if ("give" .equals (args [0 ]))
59+ if (!"give" .equals (args [0 ]) && !"add" .equals (args [0 ]) && !"remove" .equals (args [0 ]))
60+ throw new CommandNotFoundException ("commans.potion.notFound" );
61+
62+ int index = 1 ;
63+ int id = this .getPotionID (args [index ]);
64+
65+ if (id == -1 )
6066 {
61- this .givePotion (sender , Arrays .copyOfRange (args , 2 , args .length ));
67+ sender = sender .getEntityWorld ().getPlayerEntityByName (args [index ]);
68+
69+ index ++;
70+ id = this .getPotionID (args [index ]);
6271 }
63- }
64-
65- public void givePotion (ICommandSender sender , String [] args )
66- {
67- int id = this .getPotionID (args [0 ]);
72+ String name = sender .getCommandSenderName ();
73+ EntityPlayer player = getCommandSenderAsPlayer (sender );
74+
6875 int duration = 600 ;
6976 int amplifier = 0 ;
7077 boolean splash = false ;
7178
7279 if (id < 0 || id >= Potion .potionTypes .length || Potion .potionTypes [id ] == null )
7380 {
74- throw new NumberInvalidException ("commands.effect.notFound" , new Object [] { Integer .valueOf (id ) });
81+ throw new NumberInvalidException ("commands.potion. effect.notFound" , new Object [] { Integer .valueOf (id ) });
7582 }
7683
77- if (args .length >= 2 )
78- {
79- duration = parseIntBounded (sender , args [1 ], 0 , 1000000 ) * 20 ;
80- }
8184 if (Potion .potionTypes [id ].isInstant ())
8285 {
8386 duration = 1 ;
8487 }
88+ else if (args .length >= 2 )
89+ {
90+ duration = parseIntBounded (sender , args [index + 1 ], 0 , 1000000 ) * 20 ;
91+ }
92+
8593 if (args .length >= 3 )
8694 {
87- amplifier = parseIntBounded (sender , args [2 ], 1 , 256 ) - 1 ;
95+ amplifier = parseIntBounded (sender , args [index + 2 ], 1 , 256 ) - 1 ;
8896 }
8997 if (args .length >= 4 )
9098 {
91- splash = Boolean .parseBoolean (args [3 ]);
99+ splash = Boolean .parseBoolean (args [index + 3 ]);
92100 }
93101
94102 PotionEffect potioneffect = new PotionEffect (id , duration , amplifier );
95- ItemStack stack = new ItemStack (BrewingAPI .potion2 , 1 , splash ? 2 : 1 );
96- PotionType .getFromEffect (potioneffect ).apply (stack );
97-
98- EntityItem entityitem = ((EntityPlayerMP ) sender ).dropPlayerItemWithRandomChoice (stack , false );
99- entityitem .delayBeforeCanPickup = 0 ;
100- String name = sender .getCommandSenderName ();
103+ IPotionType potionType = PotionType .getFromEffect (potioneffect );
101104
102- if (splash )
105+ if ("give" .equals (args [0 ]))
106+ {
107+ ItemStack stack = new ItemStack (BrewingAPI .potion2 , 1 , splash ? 2 : 1 );
108+ potionType .apply (stack );
109+
110+ EntityItem entityitem = player .dropPlayerItemWithRandomChoice (stack , false );
111+ entityitem .delayBeforeCanPickup = 0 ;
112+
113+ if (splash )
114+ {
115+ notifyAdmins (sender , "commands.potion.give.splash.success" , potioneffect .getEffectName (), id , duration , amplifier , name );
116+ }
117+ else
118+ {
119+ notifyAdmins (sender , "commands.potion.give.success" , potioneffect .getEffectName (), id , duration , amplifier , name );
120+ }
121+ }
122+ else if ("remove" .equals (args [0 ]))
103123 {
104- notifyAdmins (sender , "commands.potion.give.splash.success" , new Object [] { new ChatComponentText (potioneffect .getEffectName ()), Integer .valueOf (id ), Integer .valueOf (duration ), Integer .valueOf (amplifier ), name });
124+ ItemStack stack = player .getHeldItem ();
125+ potionType .remove (stack );
126+
127+ notifyAdmins (sender , "command.potion.remove.success" , potioneffect .getEffectName (), id , duration , amplifier , name );
105128 }
106- else
129+ else if ( "add" . equals ( args [ 0 ]))
107130 {
108- notifyAdmins (sender , "commands.potion.give.success" , new Object [] { new ChatComponentText (potioneffect .getEffectName ()), Integer .valueOf (id ), Integer .valueOf (duration ), Integer .valueOf (amplifier ), name });
131+ ItemStack stack = player .getHeldItem ();
132+ potionType .apply (stack );
133+
134+ notifyAdmins (sender , "command.potion.remove.success" , potioneffect .getEffectName (), id , duration , amplifier , name );
109135 }
110136 }
111137
@@ -132,7 +158,7 @@ public List addTabCompletionOptions(ICommandSender sender, String[] args)
132158 {
133159 if (args .length == 1 )
134160 {
135- return getListOfStringsMatchingLastWord (args , "give" );
161+ return getListOfStringsMatchingLastWord (args , "give" , "add" , "remove" );
136162 }
137163 else if (args .length == 2 )
138164 {
0 commit comments