-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandRemove.java
74 lines (59 loc) · 1.96 KB
/
CommandRemove.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package kdx7214.necessities;
import java.util.Iterator;
import java.util.List;
import cpw.mods.fml.common.Loader;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.IMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
public class CommandRemove extends CommandBaseNecessities {
public CommandRemove() {
}
@Override
public String getCommandName()
{
return "remove";
}
@Override
public String getCommandUsage(ICommandSender par1ICommandSender)
{
return "/" + getCommandName() + " <radius>" ;
}
@Override
public void processCommand(ICommandSender sender, String[] var2)
{
assert(sender instanceof EntityPlayer || sender instanceof EntityPlayerMP) ;
if (var2.length != 1) {
sender.sendChatToPlayer(getCommandUsage(sender)) ;
return ;
}
double r = Double.parseDouble(var2[0]) ;
r *= r ;
EntityPlayer player = getCommandSenderAsPlayer(sender) ;
List mobs = player.worldObj.loadedEntityList ;
Iterator it = mobs.iterator() ;
int count = 0 ;
while (it.hasNext()) {
Object t = it.next() ;
Entity u = (Entity)t ;
double x = player.posX - u.posX ;
double y = player.posY - u.posY ;
double z = player.posZ - u.posZ ;
double dist = x*x + y*y + z*z ;
if (dist < r) {
if (t instanceof EntityItem) {
u.setDead() ;
count++ ;
}
} // if (dist < r)
} // while (it.hasNext())
sender.sendChatToPlayer("" + count + " items removed.") ;
}
@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
return hasPermission(sender, "necessities.remove", true, false) ;
} // public boolean canCommandSenderUseCommand(...)
} // public class CommandRemove