Source:
<code>public boolean execute(CommandSender sender, String label, String[] args) { if (!testPermission(sender)) { return false; } if (args.length < 1) { sender.sendMessage(ChatColor.RED + "Usage:" + usageMessage); return false; } String name = args[0]; Entity[] entities; if (name.startsWith("@")) { CommandTarget target = new CommandTarget(sender, name); <START> entities = target.getMatched(CommandUtils.getLocation(sender)); <END> if (entities.length == 0) { sender.sendMessage(ChatColor.RED + "Selector '" + name + "' found nothing."); return false; } } else { GlowPlayer player = (GlowPlayer) Bukkit.getPlayerExact(args[0]); if (player == null) { sender.sendMessage(ChatColor.RED + "Entity '" + name + "' cannot be found"); return false; } else { entities = new Entity[] {player}; } } if (args.length >= 2) { String data = String.join(" ", Arrays.copyOfRange(args, 4, args.length)); CompoundTag tag; try { tag = Mojangson.parseCompound(data); } catch (MojangsonParseException e) { sender.sendMessage(ChatColor.RED + "Invalid Data Tag: " + e.getMessage()); return false; } for (Entity entity : entities) { if (entity instanceof GlowEntity) { CompoundTag entityTag = new CompoundTag(); EntityStorage.save((GlowEntity) entity, entityTag); if (tag.matches(entityTag)) { sender.sendMessage("Found " + CommandUtils.getName(entity)); } else { sender.sendMessage(ChatColor.RED + CommandUtils.getName(entity) + " did not match the required data structure"); } } } } else { for (Entity entity : entities) { sender.sendMessage("Found " + CommandUtils.getName(entity)); } } return true; }</code><technical_language>Assuming /testfor command executed physical senders (no console), validate (see other commands target selectors)</technical_language>

Target:
public boolean execute(CommandSender sender, String label, String[] args) { if (!testPermission(sender)) { return false; } if (args.length < 1) { sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); return false; } String name = args[0]; Entity[] entities; if (name.startsWith("@")) { CommandTarget target = new CommandTarget(sender, name); entities = target.getMatched(CommandUtils.getLocation(sender)); if (entities.length == 0) { sender.sendMessage(ChatColor.RED + "Selector '" + name + "' found nothing."); return false; } } else { GlowPlayer player = (GlowPlayer) Bukkit.getPlayerExact(args[0]); if (player == null) { sender.sendMessage(ChatColor.RED + "Entity '" + name + "' cannot be found"); return false; } else { entities = new Entity[] {player}; } } if (args.length >= 2) { String data = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); CompoundTag tag; try { tag = Mojangson.parseCompound(data); } catch (MojangsonParseException e) { sender.sendMessage(ChatColor.RED + "Invalid Data Tag: " + e.getMessage()); return false; } for (Entity entity : entities) { if (entity instanceof GlowEntity) { CompoundTag entityTag = new CompoundTag(); EntityStorage.save((GlowEntity) entity, entityTag); if (tag.matches(entityTag)) { sender.sendMessage("Found " + CommandUtils.getName(entity)); } else { sender.sendMessage(ChatColor.RED + CommandUtils.getName(entity) + " did not match the required data structure"); } } } } else { for (Entity entity : entities) { sender.sendMessage("Found " + CommandUtils.getName(entity)); } } return true; }