Java 类net.minecraft.command.EntitySelector 实例源码

项目:TaleCraft    文件:SwitchShaderCommand.java   
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if(Boolean.TRUE.booleanValue()) {
        throw new CommandException("This command is not yet implemented. :(");
    }

    if(args.length != 2) {
        throw new CommandException("Wrong number of parameters: " + args.length + " given, 2 needed.");
    }

    List<EntityPlayerMP> players = EntitySelector.matchEntities(sender, args[0], EntityPlayerMP.class);
    String shaderName = args[1];

    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setString("shaderName", shaderName);
    StringNBTCommandPacket pkt = new StringNBTCommandPacket("switchShader", nbt);

    for(EntityPlayerMP entityPlayerMP : players) {
        TaleCraft.network.sendTo(pkt, entityPlayerMP);
    }

}
项目:TaleCraft    文件:MountCommand.java   
private Entity fetchEntity(ICommandSender sender, String string) throws CommandException {
    if(string.equalsIgnoreCase("this")) {
        if(sender.getCommandSenderEntity() != null) {
            return sender.getCommandSenderEntity();
        } else {
            throw new CommandException("CommandSender does not have a entity assigned.", sender, string);
        }
    }

    List<Entity> list = EntitySelector.matchEntities(sender, string, Entity.class);

    if(list.size() == 0) {
        throw new CommandException("Matched zero entitires: " + string, sender, string);
    }
    if(list.size() > 1) {
        throw new CommandException("Matched more than one ("+list.size()+") entity: " + string, sender, string);
    }

    Entity ent = list.get(0);

    if(ent == null) {
        throw new CommandException("Could not match one entity: " + string, sender, string);
    }

    return ent;
}
项目:TaleCraft    文件:URLBlockTileEntity.java   
public void trigger(EnumTriggerState triggerState) {
    if(triggerState.getBooleanValue()) {
        List<EntityPlayerMP> players = null;
        try {
            players = EntitySelector.matchEntities(this, selector, EntityPlayerMP.class);
        } catch (CommandException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        StringNBTCommandPacketClient command = new StringNBTCommandPacketClient();
        command.command = "client.gui.openurl";
        command.data = NBTHelper.newSingleStringCompound("url",url);

        for(EntityPlayerMP player : players) {
            TaleCraft.network.sendTo(command, player);
        }
    }
}
项目:Easy-Editors    文件:SyntaxSay.java   
@Override
public int readFromArgs(String[] args, int index) throws CommandSyntaxException {
    clearEntries();
    int amtRead = args.length - index;
    for (; index < args.length; index++) {
        Word word = new Word(getContext());
        if (EntitySelector.isSelector(args[index])) {
            word.getRadioList().setSelectedIndex(1);
            word.getSelector().readFromArgs(args, index);
        } else {
            word.getRadioList().setSelectedIndex(0);
            String text = args[index];
            while (index + 1 < args.length && !EntitySelector.isSelector(args[index + 1])) {
                index++;
                text = text + " " + args[index];
            }
            ((ITextField<?>) word.getTextField()).setTextAsString(text);
        }
        addEntry(word);
    }
    return amtRead;
}
项目:wizards-of-lua    文件:EntitiesModule.java   
public @Nullable Iterable<Entity> find(String target) {
  try {
    List<Entity> list = EntitySelector.<Entity>matchEntities(spellEntity, target, Entity.class);
    return list;
  } catch (CommandException e) {
    throw new UndeclaredThrowableException(e);
  }
}
项目:wizards-of-lua    文件:MinecraftBackdoor.java   
public @Nullable List<Entity> findEntities(String target) {
  try {
    ICommandSender sender = testEnv.getServer();
    List<Entity> result = EntitySelector.<Entity>matchEntities(sender, target, Entity.class);
    return result;
  } catch (CommandException e) {
    throw new UndeclaredThrowableException(e);
  }
}
项目:TaleCraft    文件:WorldObjectWrapper.java   
public List<EntityObjectWrapper> getEntities(String selector) {
    if(worldCommandSender == null) {
        worldCommandSender = new WorldCommandSender(world);
    }

    List<Entity> entities = null;
    try {
        entities = EntitySelector.matchEntities(worldCommandSender, selector, Entity.class);
    } catch (CommandException e) {
        e.printStackTrace();
    }
    return EntityObjectWrapper.transform(entities);
}
项目:TaleCraft    文件:WorldObjectWrapper.java   
public EntityObjectWrapper getEntity(String selector) {
    if(worldCommandSender == null) {
        worldCommandSender = new WorldCommandSender(world);
    }

    List<Entity> entities = null;
    try {
        entities = EntitySelector.matchEntities(worldCommandSender, selector, Entity.class);
    } catch (CommandException e) {
        e.printStackTrace();
    }
    return EntityObjectWrapper.transform(entities.get(0));
}
项目:TaleCraft    文件:FadeCommand.java   
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    int color = 0x000000;
    int time = 40;
    String texture = null;

    List<EntityPlayerMP> players = Collections.emptyList();
    if(args.length > 0) {
        players = EntitySelector.matchEntities(sender, args[0], EntityPlayerMP.class);
        if(args.length > 1){
            try{
                color = Integer.parseInt(args[1]);
                if(args.length > 2){
                    time = Integer.parseInt(args[2]);
                }
            }catch(NumberFormatException ex){
                throw new NumberInvalidException("Invalid integer!", new Object[0]);
            }

            if(args.length > 2) {
                String[] a = Arrays.copyOfRange(args, 3, args.length);
                StringBuilder b = new StringBuilder();
                for(String s : a)
                    b.append(s).append(" ");
                texture = b.toString().trim();
            }
        }
    }else{
        throw new CommandException("Incorrect usage!", new Object[0]);
    }

    for(EntityPlayerMP player : players){
        TaleCraft.network.sendTo(new FadePacket(color, time, texture), player);
    }

}
项目:TaleCraft    文件:AttackCommand.java   
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    // check if we have all needed parameters
    // If not throw a syntax error.
    if(args.length != 3) {
        throw new SyntaxErrorException("Syntax: " + getUsage(sender));
    }

    // fetch
    String str_selector = args[0];
    String str_dmgtype = args[1];
    String str_dmgamount = args[2];

    // parse all parameters
    List<EntityLivingBase> entities = EntitySelector.matchEntities(sender, str_selector, EntityLivingBase.class);
    DamageSource damage_type = AttackCommand.getDamageSource(str_dmgtype);//AttackCommand.parseDamageType(str_dmgtype);
    double damage_amount = CommandBase.parseDouble(str_dmgamount, 0, 1000);

    // check entities
    if(entities.size() == 0) {
        throw new CommandException("No entities found: " + str_selector);
    }

    // check damage type
    if(damage_type == null) {
        throw new CommandException("Unknown damage type: " + str_dmgtype);
    }

    // Attack the entities with the given damage type and amount.
    for(EntityLivingBase living : entities) {
        if(living instanceof EntityPlayerMP && ((EntityPlayerMP)living).capabilities.isCreativeMode) {
            continue;
        }

        living.attackEntityFrom(damage_type, (float) damage_amount);
    }
}
项目:morecommands    文件:PatchServerCommandManager.java   
private int getUsernameIndex(ICommand command, String[] args) throws CommandException {
    if (command == null)
        return -1;
    else {
        for (int i = 0; i < args.length; ++i)
            if (command.isUsernameIndex(args, i) && EntitySelector.matchesMultiplePlayers(args[i]))
                return i;

        return -1;
    }
}
项目:Backmemed    文件:CommandScoreboard.java   
protected void joinTeam(ICommandSender sender, String[] p_184916_2_, int p_184916_3_, MinecraftServer server) throws CommandException
{
    Scoreboard scoreboard = this.getScoreboard(server);
    String s = p_184916_2_[p_184916_3_++];
    Set<String> set = Sets.<String>newHashSet();
    Set<String> set1 = Sets.<String>newHashSet();

    if (sender instanceof EntityPlayer && p_184916_3_ == p_184916_2_.length)
    {
        String s4 = getCommandSenderAsPlayer(sender).getName();

        if (scoreboard.addPlayerToTeam(s4, s))
        {
            set.add(s4);
        }
        else
        {
            set1.add(s4);
        }
    }
    else
    {
        while (p_184916_3_ < p_184916_2_.length)
        {
            String s1 = p_184916_2_[p_184916_3_++];

            if (EntitySelector.hasArguments(s1))
            {
                for (Entity entity : getEntityList(server, sender, s1))
                {
                    String s3 = getEntityName(server, sender, entity.getCachedUniqueIdString());

                    if (scoreboard.addPlayerToTeam(s3, s))
                    {
                        set.add(s3);
                    }
                    else
                    {
                        set1.add(s3);
                    }
                }
            }
            else
            {
                String s2 = getEntityName(server, sender, s1);

                if (scoreboard.addPlayerToTeam(s2, s))
                {
                    set.add(s2);
                }
                else
                {
                    set1.add(s2);
                }
            }
        }
    }

    if (!set.isEmpty())
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_ENTITIES, set.size());
        notifyCommandListener(sender, this, "commands.scoreboard.teams.join.success", new Object[] {Integer.valueOf(set.size()), s, joinNiceString(set.toArray(new String[set.size()]))});
    }

    if (!set1.isEmpty())
    {
        throw new CommandException("commands.scoreboard.teams.join.failure", new Object[] {Integer.valueOf(set1.size()), s, joinNiceString(set1.toArray(new String[set1.size()]))});
    }
}
项目:Backmemed    文件:CommandScoreboard.java   
protected void leaveTeam(ICommandSender sender, String[] p_184911_2_, int p_184911_3_, MinecraftServer server) throws CommandException
{
    Scoreboard scoreboard = this.getScoreboard(server);
    Set<String> set = Sets.<String>newHashSet();
    Set<String> set1 = Sets.<String>newHashSet();

    if (sender instanceof EntityPlayer && p_184911_3_ == p_184911_2_.length)
    {
        String s3 = getCommandSenderAsPlayer(sender).getName();

        if (scoreboard.removePlayerFromTeams(s3))
        {
            set.add(s3);
        }
        else
        {
            set1.add(s3);
        }
    }
    else
    {
        while (p_184911_3_ < p_184911_2_.length)
        {
            String s = p_184911_2_[p_184911_3_++];

            if (EntitySelector.hasArguments(s))
            {
                for (Entity entity : getEntityList(server, sender, s))
                {
                    String s2 = getEntityName(server, sender, entity.getCachedUniqueIdString());

                    if (scoreboard.removePlayerFromTeams(s2))
                    {
                        set.add(s2);
                    }
                    else
                    {
                        set1.add(s2);
                    }
                }
            }
            else
            {
                String s1 = getEntityName(server, sender, s);

                if (scoreboard.removePlayerFromTeams(s1))
                {
                    set.add(s1);
                }
                else
                {
                    set1.add(s1);
                }
            }
        }
    }

    if (!set.isEmpty())
    {
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_ENTITIES, set.size());
        notifyCommandListener(sender, this, "commands.scoreboard.teams.leave.success", new Object[] {Integer.valueOf(set.size()), joinNiceString(set.toArray(new String[set.size()]))});
    }

    if (!set1.isEmpty())
    {
        throw new CommandException("commands.scoreboard.teams.leave.failure", new Object[] {Integer.valueOf(set1.size()), joinNiceString(set1.toArray(new String[set1.size()]))});
    }
}
项目:TaleCraft    文件:TargetedTeleportCommand.java   
/**This method either returns a list of entities with at least one entity, or it throws a {@link CommandException}.**/
private List<Entity> locateFunc(ICommandSender sender, String funcStr) throws CommandException {
    List<Entity> entitiesToTeleport = null;

    // <SELECTOR>
    // $SELF
    // <NAME>

    if(funcStr.startsWith("@")) {
        // selector
        String selector = funcStr;
        entitiesToTeleport = EntitySelector.matchEntities(sender, selector, Entity.class);

        if(entitiesToTeleport.isEmpty()) {
            throw new CommandException("No entity found: Selector "+selector+" yielded no results.");
        }
    } else if(funcStr.equalsIgnoreCase("self")) {
        // self

        // make sure the command sender has a entity wrapped
        Entity source = sender.getCommandSenderEntity();

        if(source == null) {
            throw new CommandException("Command-Sender is not a entity: Entity is null.");
        }

        entitiesToTeleport = Lists.newArrayList(source);

        if(entitiesToTeleport.isEmpty()) {
            // THIS ERROR SHOULD NOT OCCUR.
            throw new CommandException("No entity found: CommandSender is not a entity. THIS ERROR SHOULD NOT OCCUR.");
        }
    } else {
        // name
        String name = funcStr;
        entitiesToTeleport = findNamedEntity(sender.getEntityWorld(), name);

        if(entitiesToTeleport.isEmpty()) {
            throw new CommandException("No entity found: There are no entities with the name '"+name+"'.");
        }
    }

    // by this point 'entitiesToTeleport' can not possibly be null.

    return entitiesToTeleport;
}
项目:TaleCraft    文件:EditEntityCommand.java   
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if(args.length != 1) {
        throw new CommandException("Wrong number of parameters: " + args.length + " given, 1 needed.");
    }

    Entity senderEntity = sender.getCommandSenderEntity();

    if(senderEntity == null) {
        throw new CommandException("Command must be executed by a actual player. Sender has no entity.");
    }

    if(!(senderEntity instanceof EntityPlayerMP)) {
        throw new CommandException("Command must be executed by a actual player. Entity is not a player.");
    }

    EntityPlayerMP player = (EntityPlayerMP) senderEntity;
    World theWorld = sender.getEntityWorld();
    Entity theEntity = null;

    if(args[0].equalsIgnoreCase("self")) {
        theEntity = player;
    } else if(args[0].startsWith("@")) {
        List<Entity> entities = EntitySelector.matchEntities(player, args[0], Entity.class);
        if(!entities.isEmpty()) {
            theEntity = entities.get(0);
        }
    } else {
        UUID uuid = UUID.fromString(args[0]);

        for(Object entityObj : theWorld.loadedEntityList) {
            Entity entity = (Entity) entityObj;

            if(entity.getUniqueID().equals(uuid)) {
                theEntity = entity;
                break;
            }
        }
    }

    if(theEntity == null) {
        throw new CommandException("Entity not found: " + args[0]);
    }

    TaleCraft.logger.debug("Found entity to edit: " + theEntity);

    NBTTagCompound entityData = new NBTTagCompound();
    theEntity.writeToNBT(entityData);
    entityData.setString("id", theEntity instanceof EntityPlayerMP ? "Player" : EntityList.getEntityString(theEntity));

    NBTTagCompound commandData = new NBTTagCompound();
    commandData.setTag("entityData", entityData);
    commandData.setString("entityUUID", theEntity.getUniqueID().toString());

    StringNBTCommandPacketClient command = new StringNBTCommandPacketClient("client.gui.editor.entity", commandData);

    TaleCraft.logger.debug("Sending entity data for editing to player: " + player.getName());
    TaleCraft.network.sendTo(command, player);
}
项目:TaleCraft    文件:PlayerDataCommand.java   
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if(args.length < 2) {
        throw new WrongUsageException(getUsage(sender), sender, args);
    }
    List<EntityPlayerMP> list = EntitySelector.matchEntities(sender, args[0], EntityPlayerMP.class);

    String nbtS = "";
    for(int i = 1; i < args.length; i++){
        nbtS += args[i];
    }
    NBTTagCompound nbt;
    try {
        nbt = JsonToNBT.getTagFromJson(nbtS);
    } catch (NBTException e) {
        throw new CommandException("The NBT given is not in the json format!", sender, nbtS);
    }

    //Checks for blacklisted words
    if(nbt.hasKey("abilities"))throw new CommandException("The NBT given has the blacklisted tag: \"abilities\"", sender, nbtS);
    if(nbt.hasKey("Sleeping"))throw new CommandException("The NBT given has the blacklisted tag: \"Sleeping\"", sender, nbtS);
    if(nbt.hasKey("HurtTime"))throw new CommandException("The NBT given has the blacklisted tag: \"HurtTime\"", sender, nbtS);
    if(nbt.hasKey("HurtByTimestamp"))throw new CommandException("The NBT given has the blacklisted tag: \"HurtByTimestamp\"", sender, nbtS);
    if(nbt.hasKey("DeathTime"))throw new CommandException("The NBT given has the blacklisted tag: \"DeathTime\"", sender, nbtS);
    if(nbt.hasKey("FallFlying"))throw new CommandException("The NBT given has the blacklisted tag: \"FallFlying\"", sender, nbtS);
    if(nbt.hasKey("Pos"))throw new CommandException("The NBT given has the blacklisted tag: \"Pos\"", sender, nbtS);
    if(nbt.hasKey("Motion"))throw new CommandException("The NBT given has the blacklisted tag: \"Motion\"", sender, nbtS);
    if(nbt.hasKey("Rotation"))throw new CommandException("The NBT given has the blacklisted tag: \"Rotation\"", sender, nbtS);
    if(nbt.hasKey("FallDistance"))throw new CommandException("The NBT given has the blacklisted tag: \"FallDistance\"", sender, nbtS);
    if(nbt.hasKey("Fire"))throw new CommandException("The NBT given has the blacklisted tag: \"Fire\"", sender, nbtS);
    if(nbt.hasKey("Air"))throw new CommandException("The NBT given has the blacklisted tag: \"Air\"", sender, nbtS);
    if(nbt.hasKey("OnGround"))throw new CommandException("The NBT given has the blacklisted tag: \"OnGround\"", sender, nbtS);
    if(nbt.hasKey("Dimension"))throw new CommandException("The NBT given has the blacklisted tag: \"Dimension\"", sender, nbtS);
    if(nbt.hasKey("Invulnerable"))throw new CommandException("The NBT given has the blacklisted tag: \"Invulnerable\"", sender, nbtS);
    if(nbt.hasKey("PortalCooldown"))throw new CommandException("The NBT given has the blacklisted tag: \"PortalCooldown\"", sender, nbtS);
    if(nbt.hasKey("UUID"))throw new CommandException("The NBT given has the blacklisted tag: \"UUID\"", sender, nbtS);
    if(nbt.hasKey("CustomName"))throw new CommandException("The NBT given has the blacklisted tag: \"CustomName\"", sender, nbtS);
    if(nbt.hasKey("CustomNameVisible"))throw new CommandException("The NBT given has the blacklisted tag: \"CustomNameVisible\"", sender, nbtS);
    if(nbt.hasKey("Silent"))throw new CommandException("The NBT given has the blacklisted tag: \"Silent\"", sender, nbtS);
    if(nbt.hasKey("NoGravity"))throw new CommandException("The NBT given has the blacklisted tag: \"NoGravity\"", sender, nbtS);
    if(nbt.hasKey("Glowing"))throw new CommandException("The NBT given has the blacklisted tag: \"Glowing\"", sender, nbtS);

    for(EntityPlayerMP player : list){
        NBTTagCompound old = player.serializeNBT();
        old.merge(nbt);
        player.deserializeNBT(old);
    }
}
项目:morecommands    文件:PatchServerCommandManager.java   
@Override
public int executeCommand(ICommandSender sender, String rawCommand) {
    rawCommand = rawCommand.trim();

    if (rawCommand.startsWith("/"))
        rawCommand = rawCommand.substring(1);

       rawCommand = replaceVariables(sender, rawCommand);

       String[] astring = rawCommand.split(" ");
       String s = astring[0];
       astring = dropFirstString(astring);
       ICommand icommand = (ICommand)this.getCommands().get(s);
       int i = 0;

       try {
        int j = this.getUsernameIndex(icommand, astring);

        if (icommand == null) {
            TextComponentTranslation textcomponenttranslation1 = new TextComponentTranslation("commands.generic.notFound");
            textcomponenttranslation1.getStyle().setColor(TextFormatting.RED);
            sender.sendMessage(textcomponenttranslation1);
        }
        else if (icommand.checkPermission(this.getServer(), sender)) {
            net.minecraftforge.event.CommandEvent event = new net.minecraftforge.event.CommandEvent(icommand, sender, astring);

            if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(event)) {
                   if (event.getException() != null)
                    com.google.common.base.Throwables.propagateIfPossible(event.getException());

                   return 1;
               }

               if (event.getParameters() != null) 
                astring = event.getParameters();

               if (j > -1) {
                List<Entity> list = EntitySelector.<Entity>matchEntities(sender, astring[j], Entity.class);
                String s1 = astring[j];
                sender.setCommandStat(CommandResultStats.Type.AFFECTED_ENTITIES, list.size());

                   if (list.isEmpty())
                    throw new PlayerNotFoundException("commands.generic.selector.notFound", new Object[] {astring[j]});


                   for (Entity entity : list) {
                       astring[j] = entity.getCachedUniqueIdString();

                       if (this.tryExecute(sender, astring, icommand, rawCommand))
                        ++i;
                   }

                   astring[j] = s1;
               }
               else {
                   sender.setCommandStat(CommandResultStats.Type.AFFECTED_ENTITIES, 1);

                   if (this.tryExecute(sender, astring, icommand, rawCommand))
                    ++i;
              }
           }
        else {
               TextComponentTranslation textcomponenttranslation2 = new TextComponentTranslation("commands.generic.permission");
               textcomponenttranslation2.getStyle().setColor(TextFormatting.RED);
               sender.sendMessage(textcomponenttranslation2);
           }
       }
       catch (CommandException commandexception) {
           TextComponentTranslation textcomponenttranslation = new TextComponentTranslation(commandexception.getMessage(), commandexception.getErrorObjects());
           textcomponenttranslation.getStyle().setColor(TextFormatting.RED);
           sender.sendMessage(textcomponenttranslation);
       }

       sender.setCommandStat(CommandResultStats.Type.SUCCESS_COUNT, i);
       return i;
   }