Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.38 KB | None | 0 0
  1. package miscutil.core.commands;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Random;
  6.  
  7. import miscutil.core.util.Utils;
  8. import net.minecraft.command.ICommand;
  9. import net.minecraft.command.ICommandSender;
  10. import net.minecraft.entity.Entity;
  11. import net.minecraft.entity.passive.EntityVillager;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.tileentity.TileEntity;
  14. import net.minecraft.util.AxisAlignedBB;
  15. import net.minecraft.util.ChunkCoordinates;
  16. import net.minecraft.world.World;
  17.  
  18.  
  19. public class CommandMath implements ICommand
  20. {
  21.     private final List<String> aliases;
  22.  
  23.     protected String fullEntityName;
  24.     protected Entity conjuredEntity;
  25.     private int Radius = 0;
  26.  
  27.     public CommandMath()
  28.     {
  29.         aliases = new ArrayList<String>();
  30.  
  31.         aliases.add("slaughter");
  32.  
  33.         aliases.add("wipe");
  34.  
  35.     }
  36.  
  37.     @Override
  38.     public int compareTo(Object o)
  39.     {
  40.         return 0;
  41.  
  42.     }
  43.  
  44.     @Override
  45.     public String getCommandName()
  46.     {
  47.         return "Wipe";
  48.  
  49.     }
  50.  
  51.     @Override        
  52.     public String getCommandUsage(ICommandSender var1)
  53.     {
  54.         return "/wipe [Wipe Distance]";
  55.  
  56.     }
  57.  
  58.     @Override
  59.     public List<String> getCommandAliases()
  60.     {
  61.         return this.aliases;
  62.  
  63.     }
  64.  
  65.     public void processCommand(ICommandSender S, String[] argString)
  66.     {
  67.         World W = S.getEntityWorld();
  68.         CommandUtils C = new CommandUtils();
  69.         EntityPlayer P = C.getPlayer(S);
  70.         //System.out.println(P.getCommandSenderName());
  71.         //System.out.println(P.getDisplayName());
  72.         try {              
  73.             if (argString[0].equals(null) && argString.length <= 0){
  74.                 Utils.sendChatToPlayer(P, "Please enter a number after the command");
  75.                 Radius = 250;
  76.                 Utils.LOG_INFO("Setting value to 250 as default.");
  77.             }
  78.             else if (!argString[0].equals(null) || argString.length > 0){
  79.                 String commandValue = argString[0];
  80.                 if (!commandValue.equals(null)){
  81.  
  82.                     try {
  83.                         Radius = Integer.parseInt(commandValue);
  84.                         Utils.LOG_INFO("Setting value to "+Radius);
  85.                     } catch (NumberFormatException e) {
  86.                         Utils.sendChatToPlayer(P, "Please enter a number after the command");
  87.                         Radius = 250;
  88.                         Utils.LOG_INFO("Setting value to 250 as default.");
  89.                     }
  90.                     Utils.LOG_INFO("Command Value: "+commandValue);
  91.                 }
  92.                 else if (commandValue.equals(null)){
  93.                     Utils.LOG_INFO("No Value Given.");
  94.                 }
  95.             }
  96.  
  97.             else {
  98.                 //
  99.             }
  100.  
  101.             if (W.isRemote) {
  102.                 System.out.println("Not processing on Client side");
  103.             }
  104.             else {
  105.                 System.out.println("Processing on Server side - Villager/RfTools Sequencer Wipe engaged by: "+P.getDisplayName());
  106.                 ChunkCoordinates X = P.getPlayerCoordinates();
  107.                 Utils.LOG_WARNING("Player Location: "+X);
  108.                 double x1 = X.posX;
  109.                 Utils.LOG_WARNING("X1: "+x1);
  110.                 double y1 = X.posY;
  111.                 Utils.LOG_WARNING("Y1: "+y1);
  112.                 double z1 = X.posZ;
  113.                 Utils.LOG_WARNING("Z1: "+z1);
  114.                 @SuppressWarnings("unchecked")
  115.                 List<EntityVillager> e = P.worldObj.getEntitiesWithinAABB(EntityVillager.class, AxisAlignedBB.getBoundingBox(P.posX-Radius, P.posY-Radius, P.posZ-Radius, (P.posX + Radius),(P.posY + Radius),(P.posZ + Radius)));
  116.                 //Utils.LOG_INFO(e.toString());
  117.                 if (e.size() > 0) {
  118.                     int kills = 0;
  119.                     for (int i = 0; i <= e.size() - 1; i++) {
  120.                         EntityVillager em = (EntityVillager) e.get(i);
  121.                         Utils.LOG_INFO(em.toString()); 
  122.  
  123.  
  124.                         int R2 = new Random().nextInt(20);
  125.                         if (R2 > 1){
  126.                             em.setHealth(0);
  127.                             kills++;
  128.                         }
  129.                     }    
  130.                     Utils.sendChatToPlayer(P, "Kills: "+String.valueOf(kills));
  131.                     Utils.LOG_INFO("Kills: "+String.valueOf(kills));
  132.                 }
  133.  
  134.  
  135.                 @SuppressWarnings("unchecked")
  136.                 //List<TileEntity> e2 = P.worldObj.getEntitiesWithinAABB(mcjty.rftools.blocks.logic.SequencerTileEntity.class, AxisAlignedBB.getBoundingBox(P.posX-75, P.posY-75, P.posZ-75, (P.posX + 75),(P.posY + 75),(P.posZ + 75)));
  137.                 List<TileEntity> allTEs = P.worldObj.loadedTileEntityList;
  138.                 //Utils.LOG_INFO(allTEs.toString());
  139.                 if (e.size() > 0) {
  140.                     int RemovedBlocks = 0;             
  141.                     for (int i = 0; i <= allTEs.size() - 1; i++) {
  142.                         TileEntity em = (TileEntity) allTEs.get(i);
  143.  
  144.                         if (em.getClass().getName().equals("mcjty.rftools.blocks.logic.SequencerTileEntity")){
  145.                             int x = em.xCoord;
  146.                             int y = em.yCoord;
  147.                             int z = em.zCoord;
  148.                             Utils.LOG_INFO("Removing block at: [x:"+em.xCoord+"][y:"+em.yCoord+"][z:"+em.zCoord+"]");  
  149.                             P.worldObj.setBlockToAir(x, y, z);
  150.                             RemovedBlocks++;
  151.                         }
  152.                         Utils.LOG_INFO(em.toString());     
  153.                     }
  154.                     Utils.sendChatToPlayer(P, "Removed Blocks: "+String.valueOf(RemovedBlocks));
  155.                     Utils.LOG_INFO("Removed Blocks: "+String.valueOf(RemovedBlocks));
  156.                 }
  157.             }
  158.         } catch (ArrayIndexOutOfBoundsException e) {
  159.             Utils.sendChatToPlayer(P, "Please enter a number after the command, do not leave it blank");
  160.             Utils.LOG_INFO("Please enter a number after the command, do not leave it blank");
  161.         }
  162.  
  163.  
  164.     }
  165.  
  166.     @Override
  167.     public boolean canCommandSenderUseCommand(ICommandSender var1)
  168.     {
  169.         return true;
  170.  
  171.     }
  172.  
  173.     @Override  
  174.     public List<?> addTabCompletionOptions(ICommandSender var1, String[] var2)
  175.     {
  176.         // TODO Auto-generated method stub
  177.  
  178.         return null;
  179.  
  180.     }
  181.  
  182.     @Override
  183.     public boolean isUsernameIndex(String[] var1, int var2)
  184.     {
  185.         // TODO Auto-generated method stub
  186.  
  187.         return false;
  188.  
  189.     }
  190.  
  191.     public boolean playerUsesCommand(World W, EntityPlayer P, int cost)
  192.     {
  193.  
  194.  
  195.         return true;
  196.     }
  197.  
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement