OSDN Git Service

c1c07d208433166e50ea88a65b6a43a80f7054e9
[chemicraft/chemicraft.git] / common / chemicraft / util / CommandDeleteItem.java
1 package chemicraft.util;
2
3 import java.util.Iterator;
4 import java.util.List;
5
6 import net.minecraft.server.MinecraftServer;
7 import net.minecraft.src.CommandBase;
8 import net.minecraft.src.Entity;
9 import net.minecraft.src.EntityItem;
10 import net.minecraft.src.EntityPlayerMP;
11 import net.minecraft.src.ICommandSender;
12 import net.minecraft.src.World;
13
14 public class CommandDeleteItem extends CommandBase {
15
16         @Override
17         public String getCommandName() {
18                 return "delItem";
19         }
20
21         @Override
22         public void processCommand(ICommandSender var1, String[] var2) {
23                 MinecraftServer server = null;
24                 EntityPlayerMP player = null;
25                 try { server = (MinecraftServer)var1; } catch (ClassCastException e) {}
26                 try{ player = (EntityPlayerMP)var1;} catch(ClassCastException e) {}
27
28                 World world;
29                 List list;
30                 Iterator itr;
31
32                 if(server != null){
33                         if(var2.length > 0){
34                                 world = server.worldServerForDimension(Integer.parseInt(var2[0]));
35                                 list = world.loadedEntityList;
36                                 itr = list.iterator();
37                                 while(itr.hasNext()){
38                                         Entity entity = (Entity) itr.next();
39                                         if(entity instanceof EntityItem){
40                                                 entity.setDead();
41                                         }
42                                 }
43                         }else{
44                                 var1.sendChatToPlayer("Please specify the World.");
45                         }
46                 }else if(player != null){
47                         world = player.worldObj;
48                         list = world.loadedEntityList;
49                         itr = list.iterator();
50                         while(itr.hasNext()){
51                                 Entity entity = (Entity) itr.next();
52                                 if(entity instanceof EntityItem){
53                                         entity.setDead();
54                                 }
55                         }
56                 }else{
57                         var1.sendChatToPlayer("---Command Error---");
58                 }
59
60         }
61
62 }